u013929811
鲤鱼喝雪碧
2018-12-16 02:02

Timed out trying to read data from the socket stream!C#下载FTP服务器文件的时候出现的问题

5
  • 开发语言

每次下了4个文件后就出现这个问题,不知道什么原因?我想下载所有文件,代码如下:

     foreach (var ftpListItem in ftp.GetListing(path, FtpListOption.Modify | FtpListOption.Size).Where(ftpListItem => string.Equals(Path.GetExtension(ftpListItem.Name), filetype)))
              {
                  string destinationPath = string.Format(@"{0}\{1}", destinationDirectory, ftpListItem.Name);
                  using (Stream ftpStream = ftp.OpenRead(ftpListItem.FullName))
                  using (FileStream fileStream = File.Create(destinationPath, (int)ftpStream.Length))
                  {
                      var buffer = new byte[200 * 1024];
                      int count;
                      while ((count = ftpStream.Read(buffer, 0, buffer.Length)) > 0)
                      {
                          fileStream.Write(buffer, 0, count);
                      }
                  }
                  documentname.Add(ftpListItem.Name);
              }

using (Stream ftpStream = ftp.OpenRead(ftpListItem.FullName))这句代码 运行几次后就会出现上述问题

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换