C#FTP请求流锁定线程

C#FTP请求流锁定线程,ftp,stream,request,Ftp,Stream,Request,我正在创建一个用于通过FTP传输文件的C#应用程序。该代码在5个不同的系统上完美地工作,所有系统都具有良好的互联网接入能力,但我现在有一个第6个系统在关闭FTPRequest流时遇到问题。该系统位于该国的偏远地区,传输速度仅为10 KBps左右。我不知道传输速度是否与问题有关 这是我的密码 string path = "ftp://ftp.myftpsite.com/SomeDirectory/SomeFile.avi"; FtpWebRequest reqFTP = (FtpWebReque

我正在创建一个用于通过FTP传输文件的C#应用程序。该代码在5个不同的系统上完美地工作,所有系统都具有良好的互联网接入能力,但我现在有一个第6个系统在关闭FTPRequest流时遇到问题。该系统位于该国的偏远地区,传输速度仅为10 KBps左右。我不知道传输速度是否与问题有关

这是我的密码

string path = "ftp://ftp.myftpsite.com/SomeDirectory/SomeFile.avi";

FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(path));

reqFTP.Credentials = new NetworkCredential(tbUsername.Text, tbPassword.Text);
reqFTP.KeepAlive = false;

reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

reqFTP.UseBinary = true;
reqFTP.ContentLength = buffer.Length;

using (Stream strm = reqFTP.GetRequestStream())
{
   for (long l = 0; l < buffer.Length; l += 1024)
   {
      if (buffer.Length >= l + 1024)
      {
         strm.Write(buffer, (int)l, 1024);
      }
      else
      {
         int RemainingBytes = (int)(buffer.Length - l);
         strm.Write(buffer, (int)l, RemainingBytes);
      }
   }
}//Code gets stuck exiting the using statement
字符串路径=”ftp://ftp.myftpsite.com/SomeDirectory/SomeFile.avi";
FtpWebRequest请求ftp=(FtpWebRequest)FtpWebRequest.Create(新Uri(路径));
reqFTP.Credentials=新的网络凭据(tbUsername.Text,tbPassword.Text);
reqFTP.KeepAlive=false;
reqFTP.Method=WebRequestMethods.Ftp.UploadFile;
reqFTP.useBarbinary=true;
reqFTP.ContentLength=缓冲区.Length;
使用(Stream strm=reqFTP.GetRequestStream())
{
用于(长l=0;l=l+1024)
{
标准写入(缓冲区,(int)l,1024);
}
其他的
{
int RemainingBytes=(int)(buffer.Length-l);
strm.Write(缓冲区,(int)l,剩余字节);
}
}
}//代码在退出using语句时被卡住
我尝试不使用using语句并用.Close()关闭流,但它也被卡住了

我已经寻找了3天可能的解决方案和解决办法,但一直没有找到这个办法。仅供参考,此代码在与主程序不同的单独线程中运行,并且在6个系统中只有1个出现故障