Hey guys, I got this code to upload an FTP file which works great, but what do I do when I wnat to upload the contents of an entire folder? I mean, I could make a for-each but that would mean disconnecting and reconnecting to the FTP server alot of times which is just uneccesary. Any ideas?

Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://ftp.blabla.com/mybackups.zip"), System.Net.FtpWebRequest)
        request.Credentials = New System.Net.NetworkCredential("user", "pass")
        request.Method = System.Net.WebRequestMethods.Ftp.UploadFile

        Dim file() As Byte = System.IO.File.ReadAllBytes("c:\mybackups.zip")

        Dim strz As System.IO.Stream = request.GetRequestStream()
        strz.Write(file, 0, file.Length)
        strz.Close()
        strz.Dispose()

Edited 5 Years Ago by crankyslap: n/a

Not really sure since I have not uploaded anything to FTP with vb.net, but could you just not use:

Dim file() As Byte = System.IO.File.ReadAllBytes("c:\mybackups.zip")
        Dim file2() As Byte = System.IO.File.ReadAllBytes("c:\mybackups2.zip")
        Dim file3() As Byte = System.IO.File.ReadAllBytes("c:\mybackups3.zip")

        Dim strz As System.IO.Stream = request.GetRequestStream()
        strz.Write(file, 0, file.Length)
        strz.Write(file2, 0, file.Length)
        strz.Write(file3, 0, file.Length)

Do let me know if that works.:)

Managed to find something simpler using My.Computer.Network.UploadFile .

Dim myFTPaddress As String = "ftp://codeorder.net/"
        Dim myFTPuserName As String = "your username here"
        Dim myFTPuserPassword As String = "your login password here"

        Dim myFiles() As String = {"C:\test1.png", "C:\test2.png", "C:\test3.png"} '// files for testing.
        Dim sTemp As String = Nothing '// used to extract only FileName with Extenstion.

        For Each mySelectedFile As String In myFiles '// loop thru your files.
            sTemp = IO.Path.GetFileName(mySelectedFile) '// get only the file name with extension from Full Path.
            '// upload File to website.
            My.Computer.Network.UploadFile(mySelectedFile, myFTPaddress & sTemp, myFTPuserName, myFTPuserPassword)
        Next

        MsgBox("File(s) Upload Successful.", MsgBoxStyle.Information)

Edited 5 Years Ago by codeorder: n/a

This question has already been answered. Start a new discussion instead.