Results 1 to 12 of 12

Thread: [RESOLVED] FTP Uploading & Checking Worked

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    90

    Resolved [RESOLVED] FTP Uploading & Checking Worked

    I need to upload via FTP ALL files within a folder on server 2000) to a directory on a remote location (unix server)

    I would also like some form of notification should anything go wrong.

    I have either .Net 2005 or VB6 available to use for this.

    How best should I accomplish this? :

    FTP all files in local folder to remote folder
    If any/all files were not successfully transfered then
    msgbox "failed" ( I will look into emailing here though)

    thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: FTP Uploading & Checking Worked

    The WebClient.UploadFile method will upload a file and returns the server's response as a Byte array. You can use the IO.Directory.GetFiles method to get the file paths and then use a For Each loop to upload each file in turn.

    The My.Computer.Network.UploadFile method will also upload a file and allows you to display a progress dialogue. A failure will be signified by an exception.

    For more fine-grained control you can use the FtpWebRequest and FtpWebResponse classes. There are FTP libraries available on the Web that wrap these classes into a more user-friendly package. Alternatively you can create your own library or else use them directly.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    90

    Re: FTP Uploading & Checking Worked

    still struggling on this..
    Iv'e downloaded a few bits of code and tried but cant seem to find some works.?

    Please could you offer working sample code or a link to code that you think looks
    like it works ...
    If I can get the file/s uploading I have a start to build/learn on about checking how to trap if the files did not arrive.

    Cheers

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    90

    Re: FTP Uploading & Checking Worked

    ...Now been looking a while - Just about avery example is using C# ?

    I need to connect to a server 192.168.0.1 (eg)
    enter username
    enter password

    ftp upload a file from c:\files_to_ftp\* (eg)
    to /remote/path/on/server/ (eg)

    And finally I need to 'know' it got there...

    Does anyone know how to do this using VB2005?

    Regards
    Stewart

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: FTP Uploading & Checking Worked

    VB Code:
    1. Dim localPath As String 'Store local file path here.
    2. Dim remoteFolder As String 'Store remote folder here.
    3. Dim remotePath As String = IO.Path.Combine(remoteFolder, IO.Path.GetFileName(localPath))
    4. Dim userID As String 'Store remote user ID here.
    5. Dim password As String 'Store remote password here.
    6.  
    7. Try
    8.     My.Computer.Network.UploadFile(localPath, remotePath, userID, password)
    9.     MessageBox.Show("Upload successful.")
    10. Catch ex As Exception
    11.     MessageBox.Show("Upload failed.")
    12. End Try
    That's just one way. As I said, you can use a WebClient or an FtpWebRequest too. Also, the UploadFile method is overloaded so you can specify additional parameters, including whether to display a progress dialogue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    90

    Re: FTP Uploading & Checking Worked

    This errors also (Im probably doing something wrong)

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Dim localPath As String = "c:\testfiles\zztest.txt"
    4.         Dim remoteFolder As String = "ftp://192.168.0.1/test/share/path"
    5.         Dim remotePath As String = IO.Path.Combine(remoteFolder, IO.Path.GetFileName(localPath))
    6.         Dim userID As String = "xxxxxx"
    7.         Dim password As String = "xxxxxx"
    8.  
    9.         'Try
    10.         My.Computer.Network.UploadFile(localPath, remotePath, userID, password)
    11.         MessageBox.Show("Upload successful.")
    12.         'Catch ex As Exception
    13.         'MessageBox.Show("Upload failed.")
    14.         'End Try
    15.     End Sub


    I get an error on the my.computer.network line:
    Webexeption was unhandled
    The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    90

    Re: FTP Uploading & Checking Worked

    Any thoughts on why this FTP method does not work/connect ?

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    90

    Re: FTP Uploading & Checking Worked

    Even the Visual Studio help shows an FTP upload sample in C# and not VB.
    Is C# the way forward in visual studio and is learing VB.Net a backward step?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    90

    Re: FTP Uploading & Checking Worked

    This method also fails with the same error as above method:

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Using WC As New Net.WebClient
    3.             WC.Credentials = New Net.NetworkCredential("xxxxx", "xxxxx")
    4.             WC.UploadFile("ftp://192.168.0.1/test/share/zztest.txt", "c:\testfiles\zztest.txt")
    5.  
    6.         End Using
    7.  
    8.     End Sub

  10. #10
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: FTP Uploading & Checking Worked

    My.Computer.Network.UploadFile("c:\test.doc", "ftp://111.111.111.111/htdocs/test.doc", "USername", "PAssword")

    This is how I got it to work. Does anyone know how to delete a file on an ftp server?

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    90

    Re: FTP Uploading & Checking Worked

    Resolved - I ended up going back to VB6 and using an inet control - MUCH easier !!
    Thanks to all who tried

  12. #12
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [RESOLVED] FTP Uploading & Checking Worked

    Regarding the deleting of a file, check out:

    WebRequestMethods.Ftp.DeleteFile

    Google it and you will get your answer
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width