我目前正在尝试从ftp位置下载一个大文件(1.13gb),它正在超时。
当我检查下载时,服务器上每10分钟仅下载约350mb。除了增加request.Timeout到差不多一个小时(!!)之外,有更好的方法来下载和流式传输这样的大文件。
以下是我目前使用的代码:
private void DownloadFromFtp(IFeedProviderConfiguration configuration, string urlData)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(urlData);
if (!string.IsNullOrEmpty(configuration.Username))
{
request.Credentials = new NetworkCredential(configuration.Username, configuration.Password);
}
request.ReadWriteTimeout = 600000;
request.Timeout = 600000;
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
var stream = GetUnCompressFromStream(urlData, response.GetResponseStream());
/*StreamReader reader = new StreamReader(responseStream);
documentContent = reader.ReadToEnd();
reader.Close();*/
this.WriteToFile(stream, this._localFile);
stream.Close();
}