Click here to Skip to main content
15,072,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually I created a ftp web page which can download, upload, delete.
This is the code for downloading a particular file from ftp server:
VB
Dim myFtpWebRequest As FtpWebRequest
Dim myFtpWebResponse As FtpWebResponse
Dim myStreamWriter As StreamWriter

myFtpWebRequest =WebRequest.Create("ftp:/ftp page/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()

This code is working perfect and I can download. But it is downloading the particular file into the web page folder which I created now.
Example: C:\Documents and Settings\Sadhish\My Documents\Visual Studio 2008\WebSites\WebSite4

How can I download a particular file in desktop or C drive.
Example C:/file/downloadfiles

Thanks in advances.
Posted
Updated 17-Nov-10 0:29am
v2
Comments
Sandeep Mewara 17-Nov-10 6:29am
   
Use PRE tags to format your code part. It makes the question readable.

1 solution

You hardly have to change a thing. Change this line:

myStreamWriter = New StreamWriter(Server.MapPath(filename.ext))


to:

myStreamWriter = New StreamWriter("C:\file\downloadfiles\filename.ext")


further reading:

[http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx]

hope it helps
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900