Question

i have got a remote machine which i can access using ftp (it has static ip with userid and pass). i am able to send file to that location using FTP through asp.net but don't know how to get that file back using asp.net through code. actually wants 2 things using asp.net code: 1. get file from remote machine which has static ip and userid & pass. 2. after getting that file delete that file from remote machine.

please provide me solution Thanks

Was it helpful?

Solution 2

Finally i got the solution:

Protected Sub btnDownloadFile_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myFtpWebRequest As FtpWebRequest
Dim myFtpWebResponse As FtpWebResponse
Dim myStreamWriter As StreamWriter

myFtpWebRequest = WebRequest.Create("ftp://ftp_server_name/filename.ext")

'myFtpWebRequest.Credentials = New NetworkCredential("username", "password")

myFtpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile
myFtpWebRequest.UseBinary = True

myFtpWebResponse = myFtpWebRequest.GetResponse()

myStreamWriter = New StreamWriter(Server.MapPath("filename.ext"))
myStreamWriter.Write(New StreamReader(myFtpWebResponse.GetResponseStream()).ReadToEnd)
myStreamWriter.Close()

litResponse.Text = myFtpWebResponse.StatusDescription

myFtpWebResponse.Close()
End Sub

http://dotnetacademy.blogspot.com/2010/12/how-to-upload-download-delete-file.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top