Solved

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

Posted on 2014-08-01
7
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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