

ReqFTP.Credentials = new NetworkCredential("userName", "passWord") įtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse() ReqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri)) String fileName = downloadFile = new FileInfo(fileName) įileStream outputStream = new FileStream(fileName, FileMode.Append) I tried to use FTPClient as suggested above and got the same timeout error, FTPClient uses FtpWebRequest so I must be missing something but I don't see the point.Īfter some more research I found that -1 is the value for infinityįor my purpose it is okay to use infinity so I went with that, problem solved.

Return ((FtpWebResponse)myReq.GetResponse()).StatusDescription Logger.logActivity( " FTP received " + String.Format( "", bytesRead ) + " bytes" ) ReadCount = ftpStream.Read( buffer, 0, bufferSize ) Ĭonsole.Write( '.' ) // show progress on the console _OutputFile.Write( buffer, 0, readCount ) ReadCount = ftpStream.Read(buffer, 0, bufferSize) Stream ftpStream = myResp.GetResponseStream() MyReq.Credentials = new NetworkCredential(_ID, _Password) įtpWebResponse myResp = (FtpWebResponse)myReq.GetResponse() MyReq = (FtpWebRequest)FtpWebRequest.Create(new Uri(this.DownloadURI)) _OutputFile = new FileStream(_SourceFile, FileMode.Create) I'm having a hell of a time understanding what's going wrong.Ĭan anyone suggest how I can instrument this code to get more insight into what's going on, or a better way to download this file? Should I increase the buffer size? By how much? Avoid the buffered writes to disk and try to swallow the whole file in memory? Any advice appreciated!. When I download the file interactively using a graphical client like LeechFTP, the downloads almost never hang, and complete in about 45 seconds. In my app log, I get a line like: > Unable to read data from the transport

Around 50% of the time, the download hangs and eventually times out. I'm using the following C# code to FTP a ~40MB CSV file from a remote service provider.
