locked
FTP Upload RRS feed

  • Question

  • User-150799291 posted

    I'm trying to create a page which uploads a daily file to my FTP server. The end user has XP Pro SP3. Here is the code and the following error I receive:

        Sub UpLoad4(ByVal Source As Object, ByVal e As EventArgs)
            ' set up request...
            Dim clsRequest As System.Net.FtpWebRequest = _
                DirectCast(System.Net.WebRequest.Create("ftp://myFTPserver/Daily/test.txt"), System.Net.FtpWebRequest)
            clsRequest.Credentials = New System.Net.NetworkCredential("userftp", "passftp")
            clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

            ' read in file...
            Dim bFile() As Byte = System.IO.File.ReadAllBytes("C:\test.txt")

            ' upload file...
            Dim clsStream As System.IO.Stream = _
                clsRequest.GetRequestStream()
            clsStream.Write(bFile, 0, bFile.Length)
            clsStream.Close()
            clsStream.Dispose()
        End Sub

     

    Server Error in '/Daily' Application.

    Could not find file 'C:\test.txt'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.IO.FileNotFoundException: Could not find file 'C:\test.txt'.

    Source Error:

    Line 32: 
    Line 33:         ' read in file...
    Line 34:         Dim bFile() As Byte = System.IO.File.ReadAllBytes("C:\test.txt")
    Line 35: 
    Line 36:         ' upload file...

    Thank you in advance.

    Monday, July 27, 2009 2:05 PM

Answers

  • User437720957 posted

    Yes agreed, but the file 'C:\test.txt' is present on the user's machine.

    On the user's machine, yes, but the path refers to a file on the web server. There is no way to "invisibly" upload a file from the user's machine.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2009 6:04 PM
  • User-150799291 posted

    Hmm... got it. Back to scheduling batch file scripts. Thank you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2009 6:42 PM

All replies

  • User437720957 posted

    Well, the error message is pretty clear, isn't it?

    Could not find file 'C:\test.txt'.

    Also, I can recommend the WebClient class for such things...

    http://windowsdevcenter.com/pub/a/windows/2006/12/12/building-ftp-services-using-net-20.html

    Monday, July 27, 2009 3:39 PM
  • User-150799291 posted

    Yes agreed, but the file 'C:\test.txt' is present on the user's machine. So, the "Error" tends to be a little misleading. I'll look at the link you provided for the WebClient class and give that a go. 

    Monday, July 27, 2009 5:50 PM
  • User437720957 posted

    Yes agreed, but the file 'C:\test.txt' is present on the user's machine.

    On the user's machine, yes, but the path refers to a file on the web server. There is no way to "invisibly" upload a file from the user's machine.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2009 6:04 PM
  • User-150799291 posted

    Hmm... got it. Back to scheduling batch file scripts. Thank you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2009 6:42 PM