FTP 経由でファイルを転送するための C# アプリを作成しています。コードは、適切なインターネット アクセスを備えた 5 つの異なるシステムで問題なく動作しましたが、FTPRequest ストリームを閉じるのに問題がある 6 番目のシステムが現在あります。このシステムは国の僻地にあり、約 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
using ステートメントを使用せずに .Close() でストリームを閉じてみましたが、そこでスタックします。
考えられる解決策と回避策を3日間探していましたが、これを理解できませんでした. 参考までに、このコードはメイン プログラムとは別のスレッドで実行され、6 つのシステムのうち 1 つだけで失敗します。