Solved

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

Posted on 2014-08-01
7
197 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

26 Experts available now in Live!

Get 1:1 Help Now