CODICE VISUAL STUDIO 2010 - VISUAL BASIC .NET - VB.NET:
Private Server As String = "127.0.0.1"
Private UserNameFTP As String = "Username"
Private PasswordFTP As String = "Password"
Private FtpDirectory As String = "cartella_upload"
Private Sub UploadFile(ByVal UpFile As String, Optional FileRename As String = Nothing)
If FileRename = "" Then FileRename = System.IO.Path.GetFileName(UpFile)
If Mid$(FtpDirectory, 1, 1) <> "/" Then FtpDirectory = "/" + FtpDirectory
If PasswordFTP <> "" Then Server = "ftp://" & UserNameFTP & ":" _
& PasswordFTP & "@" & Server
If PasswordFTP = "" Then Server = UserNameFTP & "@" & _
Server
Dim Request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create _
(Server & FtpDirectory & "/" & FileRename), System.Net.FtpWebRequest)
Request.Credentials = New System.Net.NetworkCredential(UserNameFTP, PasswordFTP)
Request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
Request.UseBinary = False '(Default is true, False is for text)
Dim bFile() As Byte = System.IO.File.ReadAllBytes(UpFile)
Dim cStream As System.IO.Stream = Request.GetRequestStream()
cStream.Write(bFile, 0, bFile.Length)
cStream.Close()
cStream.Dispose()
End Sub
By ImaginSystems & Queen Gin