下载完整的目录与子目录与FTP c#

本文关键字:子目录 FTP 下载 | 更新日期: 2023-09-27 18:12:22

如何从ftpserver下载完整目录?

我可以下载这个文件:

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

有人能帮帮我吗?

下载完整的目录与子目录与FTP c#

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

抓住右下角的小框并拉伸它以获得代码。它缺少OnDownloadFilesOrCreateDirectory函数和其他一些混乱但很明显,代码是用来递归目录的如果你想卷起袖子使用它