c# - C# FTP 挂在大文件上
问题描述
我看过其他帖子,但我读过的帖子都没有一个真正有效的答案。所以这些帖子没有帮助。我已经尝试了我看到的每一个建议。
简而言之:此例程非常适合中小型文件。但是一旦我达到大约 1 GB,它就会挂起。任何帮助是极大的赞赏。
System.Net.ServicePointManager.Expect100Continue = false;
System.Diagnostics.Trace.WriteLine("FTP: Download " + this._URL + fixURL(this._Folder).Replace("\\", "/") + fixURL(ftpFileName));
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(this._URL + fixURL(this._Folder).Replace("\\", "/") + fixURL(ftpFileName));
ftpRequest.Credentials = new NetworkCredential(this._UserName, this._Password);
ftpRequest.UsePassive = false;
ftpRequest.KeepAlive = true;
ftpRequest.UseBinary = true;
ftpRequest.Timeout = -1;
ftpRequest.ReadWriteTimeout = 1000 * 60 * 60 * 5;
ftpRequest.ServicePoint.ConnectionLimit = 1000;
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
using (FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse())
{
using (Stream ftpStream = ftpResponse.GetResponseStream())
{
ftpStream.ReadTimeout = 1000 * 60 * 60 * 5;
using (FileStream fileStream = File.Create(outFolder + @"\" + ftpFileName))
{
Byte[] buffer = new Byte[8092];
Int32 bytesRead = ftpStream.Read(buffer, 0, buffer.Length);
Int64 bytessofar = bytesRead;
System.Diagnostics.Trace.WriteLine("FTP: Download Read Block " + bytessofar.ToString("0"));
while (bytesRead > 0)
{
fileStream.Write(buffer, 0, bytesRead);
bytesRead = ftpStream.Read(buffer, 0, buffer.Length);
bytessofar += bytesRead;
System.Diagnostics.Trace.WriteLine("FTP: Download Read Block " + bytessofar.ToString("0"));
}
}
ftpRequest.Abort();
}
}
解决方案
推荐阅读
- jupyter-notebook - 如何在 Jupyter Notebook 中禁用工具提示建议
- amazon-web-services - AWS CDK 事件桥和 api 网关 AWS 示例不起作用
- python - 在python中将一列附加到现有的csv文件
- json - React Native 下载多个 JSON 并合并
- r-markdown - Rmarkdown 生成双倍行距目录
- android - DragShadowBuilder 在 Android 11 中不工作
- javascript - 我正在编写一个javascript函数来返回数组中任何给定数字的斐波那契
- node.js - 从另一个文件夹映射访问
- java - 用于 consumerBatchEnabled 侦听器的 Rabbitmq 单元测试
- python - shutil 移动基于 csv 文件名