Solved

How can I build an ASP.NET site to catch files from Computer.Network.UploadFile

Posted on 2014-08-01
7
195 Views
Last Modified: 2014-09-10
I have a Windows app that uses Computer.Network.UploadFile to FTP files to our servers.  I want to start using HTTPS rather than FTP.  According to MS here (http://msdn.microsoft.com/en-us/library/dfkdh7eb(v=vs.90).aspx) this is possible but they never explain how.  They reference 'upload.aspx' but I can't find any information on what this site needs to include.  I need this to be a protected site so the UN and PW field will be included in the Computer.Network.UploadFile call.
0
Comment
Question by:RobertBroach
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40236196
Here is an example of an .aspx that can accept uploaded files (if that is what you are looking for):

WebClient.UploadFile Method (String, String, String)
http://msdn.microsoft.com/en-us/library/vstudio/esst63h0(v=vs.100).aspx

<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Net"%>
<%@ Import NameSpace="System.Web"%>

<Script language="VB" runat=server>
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Dim f As String
        Dim file
        For Each f In Request.Files.AllKeys
            file = Request.Files(f)
            file.SaveAs("c:\inetpub\test\UploadedFiles\" & file.FileName)
        Next f

    End Sub

</Script>
<html>
<body>
<p> Upload complete. </p>
</body>
</html>

Open in new window

0
 

Author Comment

by:RobertBroach
ID: 40239258
Bob,

Thanks for the reply.  This looks very promising but I don't see how to use the UN and PW to upload to a password protected site (standard authentication using Active Directory) with WebClient.UploadFile.  Does this only allow uploads to public sites?

With Computer.Network.UploadFile and FTP we just include the UN and PW and it works great.  MS implies here(http://msdn.microsoft.com/en-us/library/w3kksch7(v=vs.90).aspx) that it can be done.

Todd
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40239292
Please refresh my memory on how you use FTP to pass those fields, please.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:RobertBroach
ID: 40239324
Bob,

The Computer.Network.UploadFile method (http://msdn.microsoft.com/en-us/library/dfkdh7eb(v=vs.90).aspx) has UN and PW parameters.  The MSDN page says that the address parameter can use either the FTP or HTTP protocol.  We have been using this method in our Windows app to FTP files from clients computers to our servers for almost 10 years.  We want to add the option to use HTTPS because we have some corporate environments where we have trouble with FTP (firewalls, ports, antivirus software...).  We also want to switch to HTTPS to protect our clients UNs and PWs when transmitted over the internet.

Todd
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40239355
Do you mean "user name" and "password" parameters?  If so, then you can pass encrypted arguments in the query string parameters to the web page, and check those values on the web site side with the Request.QueryString collection.

P.S. Here is some good reading about "clarity" and "brevity":  

Brevity and Clarity
http://blogvault.net/brevity-and-clarity/

Clarity and brevity go hand in hand. It’s sometimes tempting to sacrifice one for the other but that is a slippery path to walk on.  You cannot skip essential details and assume that your reader knows everything. Brevity is part of clarity; some even say that it is the soul of clarity. Aren’t both one and the same, you may ask? Not quite! You can be brief and unclear or clear and verbose! The magic mantra is to be clear and brief at the same time.

I find acronyms to be brief and unclear.
0
 

Author Comment

by:RobertBroach
ID: 40239441
Bob,

UN = 'userName'
PW = 'password'

I am trying to use the Computer.Network.UploadFile method that is used in our current application that is installed on close to 100 client's computers.  I can't change that as it is not practical for me to re-install all of those current installations.  If I can figure out how to build the 'upload.aspx' page that is referred to in the MSDN article (including the user credentials) then it is a solution that I can make work.

Todd
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 40239608
Here is an example that you can use in upload.aspx, referencing query string parameters:

 Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Dim userName As String = Request.QueryString("userName")
        Dim password As String = DecryptPassword(Request.QueryString("password"))

        If Not ValidateLogin(userName, password) Then Return

        Dim f As String
        Dim file
        For Each f In Request.Files.AllKeys
            file = Request.Files(f)
            file.SaveAs("c:\inetpub\test\UploadedFiles\" & file.FileName)
        Next f

    End Sub

Open in new window


URL example:
My.Computer.Network.UploadFile ( "C:\My Documents\Order.txt", "http://www.cohowinery.com/upload.aspx?userName=Bob&password=ADEE3D03AE")
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now