鲤鱼没空 2018-12-16 02:02 采纳率: 0%
浏览 1194
已结题

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

每次下了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条回答 默认 最新

  • threenewbee 2018-12-16 05:23
    关注

    服务器本身拒绝你大量下载(可能性不大)
    网路不稳定或者服务器不稳定。把超时设置大一些,或者遇到无法下载,就try+catch再重试。

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?