嘿,我一直在寻找一种解决方案,如果网络连接丢失,则抛出 Web 异常,我输入ReadWriteTimeout
了 8 秒,但拔掉插头时仍然没有抛出异常。我将 filezilla 服务器上的传输超时更改为 0。
还有另一种方法可以做到这一点我错过了吗?!非常感谢您提供任何信息。
ftpWebReq.Credentials = credens;
ftpWebReq.Method = WebRequestMethods.Ftp.UploadFile;
ftpWebReq.KeepAlive = false;
ftpWebReq.ServicePoint.ConnectionLimit = 1000;
ftpWebReq.UseBinary = true;
ftpWebReq.Timeout = 30000000;
ftpWebReq.ReadWriteTimeout = 8000;
using(FileStream fs = File.OpenRead(file.FullName))
using (ftpstream = ftpWebReq.GetRequestStream())
{
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ftpstream.Write(buffer, 0, buffer.Length);
}