问题描述
实际上,我创建了一个ftp网页,可以下载,上传,删除.
这是从ftp服务器下载特定文件的代码:
Actually I created a ftp web page which can download, upload, delete.
This is the code for downloading a particular file from ftp server:
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()
这段代码运行完美,我可以下载.但这会将特定文件下载到我现在创建的网页文件夹中.
示例:C:\ Documents and Settings \ Sadhish \ My Documents \ Visual Studio 2008 \ WebSites \ WebSite4
如何在台式机或C驱动器中下载特定文件.
示例C:/file/downloadfiles
在此先感谢您.
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.
推荐答案
myStreamWriter = New StreamWriter(Server.MapPath(filename.ext))
至:
to:
myStreamWriter = New StreamWriter("C:\file\downloadfiles\filename.ext")
进一步阅读:
[ http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx ]
希望对您有帮助
further reading:
[http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx]
hope it helps
这篇关于FTP下载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!