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

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再重试。

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站