I have seen other posts on this, but none of the posts that I have read have an answer that really seems to work. So those posts do not help. I've tried every suggestion that I've seen.
In short: This routine works perfect for small and medium files. But once I get up to about 1 GB, it hangs. Any help is greatly appreciated.
System.Net.ServicePointManager.Expect100Continue = false;
System.Diagnostics.Trace.WriteLine("FTP: Download " + this._URL + fixURL(this._Folder).Replace("\\", "/") + fixURL(ftpFileName));
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(this._URL + fixURL(this._Folder).Replace("\\", "/") + fixURL(ftpFileName));
ftpRequest.Credentials = new NetworkCredential(this._UserName, this._Password);
ftpRequest.UsePassive = false;
ftpRequest.KeepAlive = true;
ftpRequest.UseBinary = true;
ftpRequest.Timeout = -1;
ftpRequest.ReadWriteTimeout = 1000 * 60 * 60 * 5;
ftpRequest.ServicePoint.ConnectionLimit = 1000;
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
using (FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse())
{
using (Stream ftpStream = ftpResponse.GetResponseStream())
{
ftpStream.ReadTimeout = 1000 * 60 * 60 * 5;
using (FileStream fileStream = File.Create(outFolder + @"\" + ftpFileName))
{
Byte[] buffer = new Byte[8092];
Int32 bytesRead = ftpStream.Read(buffer, 0, buffer.Length);
Int64 bytessofar = bytesRead;
System.Diagnostics.Trace.WriteLine("FTP: Download Read Block " + bytessofar.ToString("0"));
while (bytesRead > 0)
{
fileStream.Write(buffer, 0, bytesRead);
bytesRead = ftpStream.Read(buffer, 0, buffer.Length);
bytessofar += bytesRead;
System.Diagnostics.Trace.WriteLine("FTP: Download Read Block " + bytessofar.ToString("0"));
}
}
ftpRequest.Abort();
}
}