vbnet FTP a file

'thanks to: http://www.eggheadcafe.com/community/aspnet/14/10028910/ftp-a-file.aspx

'Create a FTP Request Object and Specfiy a Complete Path 
Dim reqObj As FtpWebRequest = WebRequest.Create("ftp://ftp.test.net/test.txt")

'Call A FileUpload Method of FTP Request Object
reqObj.Method = WebRequestMethods.Ftp.UploadFile

'If you want to access Resourse Protected You need to give User Name and PWD
reqObj.Credentials = New NetworkCredential(uname, pwd)

'FileStream object read file from Local Drive
Dim streamObj As FileStream = System.IO.File.OpenRead("c:\test")

'Store File in Buffer
Dim buffer(streamObj.Length) As Byte

'Read File from Buffer
streamObj.Read(buffer, 0, buffer.Length)

'Close FileStream Object Set its Value to nothing
streamObj = Nothing

'Upload File to ftp://localHost/ set its object to nothing
reqObj.GetRequestStream().Write(buffer, 0, buffer.Length)
reqObj = Nothing
Uploads a file via FTP.

Updated: Thursday 7th October 2010, 03:59pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.