Hi i need help with this code to upload one exe to multiple ftp servers.
i have a file with all the links i need and user names and passwords , now it only uploads the first time every on after that gets the error invalid uri even though its correct.
-----------------------------------------------------------------------
Imports System.Net
Imports System.IO
Imports System.Data.SqlClient
Public Class Formftp
Private Sub Buttonftp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonftp.Click
Dim locat, combind, str As String
locat = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location)
combind = System.IO.Path.Combine(locat, "FTPstr.cfg")
Dim reader As New StreamReader(combind)
str = reader.ReadToEnd()
Dim TestArray() As String = str.Split(",")
Dim strftp As String
Dim s As Boolean
For t As Integer = 0 To TestArray.Length - 1
strftp = TestArray(t).ToString()
Dim TestFTPArray() As String = strftp.Split("/")
Dim di As New IO.DirectoryInfo(locat + "\ftp")
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo
For Each dra In diar1
Try
Dim struri As String = String.Format("ftp://{0}/{1}/{2}", TestFTPArray(0), TestFTPArray(1), dra)
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create(struri), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential(TestFTPArray(2), TestFTPArray(3))
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
Dim st As String = String.Format("{0}{1}{2}", locat, "\ftp\", dra)
Dim bFile() As Byte = System.IO.File.ReadAllBytes(st)
Dim clsStream As System.IO.Stream = _
clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Close()
clsStream.Dispose()
clsRequest.Abort()
Catch ex As Exception
End Try
Next
Next
End Sub
End Class
update 2012/07/30:
i tested with one exe(trying to put it to multiple servers) it uploads it to the first ftp server then when connecting to the second and every ftp server after it it says "Invalid URI: The hostname could not be parsed." on the (
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create(struri), System.Net.FtpWebRequest)
) line
even though i can use the exact same destination ftp://ip/folder/ in a browser ect with the username and password as is in the file it is reading and open the ftp folder in the browser. So there is no problem with the ftp folder itself , just the code doesn't want to ftp the exe to a second or third ftp server.