Application Hangs on FTPWEBRequest Upload if Net connection lost

193 Views Asked by At

Hey I've been looking for a solution to throw a web exception if net connection is lost, I put in ReadWriteTimeout to be 8 seconds, but still doesn't throw an exception when I pull the plug. I changed Transfer timeout on filezilla server to 0.

Is there another way to do this I'm missing?! Thanks so much in advance for any info.

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);
}
0

There are 0 best solutions below