如何从ftpserver下载完整目录?
我可以用这1个文件下载:
try
{
string strUri = strDsiteAdres+ "//" + file+"/";
Uri serverUri = new Uri(strDsiteAdres);
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return;
}
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(strUri);
reqFTP.Credentials = new NetworkCredential(strDusername, strDpassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream responseStream = response.GetResponseStream();
FileStream writeStream = new FileStream(strPath +"/"+ file, FileMode.Create);
int Length = 2048;
Byte[] buffer = new Byte[Length];
int bytesRead = responseStream.Read(buffer, 0, Length);
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream.Read(buffer, 0, Length);
}
writeStream.Close();
response.Close();
}
有人可以帮帮我吗?
答案 0 :(得分:1)
您可以查看http://www.laedit.net/fr/Framework/code/Net-FTPClient.html
抓住右下角的小盒子并伸展它以获取代码。它有一个缺少函数OnDownloadFilesOrCreateDirectory和一些其他的混乱,但很明显,如果你想用它卷起你的袖子,代码是在那里递归