I have the following code;
/// <summary>
/// Gets a file
/// </summary>
/// <param name="filename"> The filename to get. </param>
/// <returns> A list, containing each line of the file </returns>
public IEnumerable<string> GetFileLines(string filename)
{
var list = new List<string>();
var uri = BuildUri(filename);
var request = (FtpWebRequest)WebRequest.Create(uri.Uri);
request.Method = WebRequestMethods.Ftp.DownloadFile;
using (var resp = (FtpWebResponse)request.GetResponse())
{
using (var stream = resp.GetResponseStream())
{
Thread.Sleep(10000);
if (stream != null)
{
using (var responseStream = new StreamReader(stream))
{
// If we still have characters to process
while (responseStream.Peek() >= 0)
{
var line = responseStream.ReadLine();
list.Add(line);
}
}
}
}
}
return list;
}
However it is not pulling the whole file from the FTP- it seems to cut off before the end of the file has finished downloading.
Is there anything I can add to extend the time it allows to retrieve the data?
Thanks,
David
Instead of
responseStream.Peek, use below code (You can also removeThread.Sleepsafely)