Note that there are some explanatory texts on larger screens.

plurals
  1. PODownloading large files(~150MB) from FTP server hangs
    primarykey
    data
    text
    <p>I am trying to download files from ftp server with this code:</p> <pre><code>using (System.IO.FileStream fileStream = System.IO.File.OpenWrite(filePath)) { byte[] buffer = new byte[4096]; int bytesRead = responseStream.Read(buffer, 0, 4096); while (bytesRead &gt; 0) { fileStream.Write(buffer, 0, bytesRead); bytesRead = responseStream.Read(buffer, 0, 4096); } } </code></pre> <p>The creation of responseStream:</p> <pre><code>System.IO.Stream responseStream = GetFileAsStream(url, username, password, false); public static System.IO.Stream GetFileAsStream(string ftpUrl, string username, string password, bool usePassive) { System.Net.FtpWebRequest request = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(ftpUrl); request.KeepAlive = false; request.ReadWriteTimeout = 120000; request.Timeout = -1; request.UsePassive = usePassive; request.Credentials = new System.Net.NetworkCredential(username, password); request.Method = System.Net.WebRequestMethods.Ftp.DownloadFile; System.IO.Stream fileResponseStream; System.Net.FtpWebResponse fileResponse = (System.Net.FtpWebResponse)request.GetResponse(); fileResponseStream = fileResponse.GetResponseStream(); return fileResponseStream; } </code></pre> <p>It works fine with smaller files but when a file is bigger (e.g. 150mb) the process hangs. For some reason the program does not understand that it has completed the download and it still tries to read more bytes.</p> <p>I prefer answers which do not include using external libraries. Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload