1

如何从 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(); 
        }

有人可以帮帮我吗?

4

1 回答 1

1

您可以查看http://www.laedit.net/fr/Framework/code/Net-FTPClient.html

抓住右下角的那个小盒子并拉伸它以获取代码。它有一个缺失的函数 OnDownloadFilesOrCreateDirectory 和其他一些混乱,但很明显,如果你想卷起袖子,代码就可以递归目录

于 2013-05-07T13:25:35.437 回答