I am downloading a file from FTP using this code:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(downloadPath);
request.UsePassive = false;
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(_ftpUser, _ftpPass);
using (var response = (FtpWebResponse)request.GetResponse())
using (var responseStream = response.GetResponseStream())
using (var writer = new FileStream(savePath, FileMode.Create))
{
long length = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[2048];
readCount = responseStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
writer.Write(buffer, 0, readCount);
readCount = responseStream.Read(buffer, 0, bufferSize);
}
}
It works but the file is large and when I download the file with Filezilla client it is much much faster.
Is this to do with the buffer size? What ways can I make this faster?