Question FtpWebRequest Download file and save to local folder

officegrabs

New member
Joined
Aug 23, 2010
Messages
1
Programming Experience
Beginner
hi

i am trying to creat a small exe that each time the use will open the exe it shuold download a file callled sku.csv from a tfp server and save it to a local disc

here is the code i wrote untill now

VB.NET:
Expand Collapse Copy
 Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://office.com/Export/sku.csv"), System.Net.FtpWebRequest)
        request.Credentials = New System.Net.NetworkCredential("user", "password")
        request.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

how do i tell the program the path where to save the file to my local disc????
 
There are various ways to download a file and you've chosen the most complex. If you use an FtpWebRequest then you must get the response, get the data from the response and then save the data yourself. If you don't need the extra functionality that the FtpWebRequest provides then there's no point putting up with the extra complexity. The WebClient class is simpler and the My.Computer.Network object is simpler still. You simply call My.Computer.Network.DownloadFile and provide the remote address, local path and the credentials. That's it; one line of code.
 
Back
Top