Before discuss FTP client upload source code, the first must be understanding type of FTP Server mode, first is Active mode and Passive mode for second.
In passive mode, the client has no control over what port the server chooses for the data connection. Therefore, in order to use passive mode, you’ll have to allow outgoing connections to all ports in your firewall.
In active mode, the client opens a socket and waits for the server to establish the transfer connection.
The source code is here :
' sHost = url:port/folder/filename Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(sHost & "/" & sFile), System.Net.FtpWebRequest) ' only for PASV mode ' request.UsePassive = False request.Credentials = New System.Net.NetworkCredential(sFTPUser, sFTPPwd) request.Method = System.Net.WebRequestMethods.Ftp.UploadFile ' sFile is filename Dim file() As Byte = System.IO.File.ReadAllBytes(sFile) Dim strz As System.IO.Stream = request.GetRequestStream() strz.Write(file, 0, file.Length) strz.Close() strz.Dispose()
if you have problem .GetRequestStream() is error 421 can not create socket, please FTP mode PASV/ACTIVE. If you want auto upload can combine with Timer Controler