2013-05-07 83 views
1

如何從ftpserver下載完整目錄?使用FTP下載具有子目錄的完整目錄C#

我可以用這個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

你需要一些第三方組件來完成這項工作。 FtpWebRequest不是爲你的任務設計的。 – 2013-05-07 12:39:40

回答