ftp - System.Net.FtpClient.FtpCommandException:指定的网络名称不再可用
问题描述
下面的代码从 FTP 服务器获取文件并将它们存储在本地。
它适用于 1.8 GB 的文件大小,抛出 System.Net.FtpClient.FtpCommandException: The specified network name is no longer available when it is around 1.99 GB
var destinationPath = Path.Combine(path, ftpListItem.Name);
ftpClient.ReadTimeout = 45000;
ftpClient.SocketKeepAlive = true;
using (var ftpStream = ftpClient.OpenRead(ftpListItem.FullName))
{
int bufferToRead = 8;
int buffSize = (int)ftpStream.Length == 0 ? 1 : (int)ftpStream.Length;
using (var fileStream = File.Create(destinationPath, buffSize))
{
var buffer = new byte[bufferToRead * 1024 * 1024];
int count;
while ((count = ftpStream.Read(buffer, 0, buffer.Length)) > 0)
{
fileStream.Write(buffer, 0, count);
}
}
}
在 fileStream.Write(buffer, 0, count); 行抛出异常
例外
System.Net.FtpClient.FtpCommandException: The specified network name is no longer available.
at System.Net.FtpClient.FtpClient.CloseDataStream(FtpDataStream stream)
at System.Net.FtpClient.FtpDataStream.Close()
at System.Net.FtpClient.FtpSocketStream.Dispose()
at Batch_FtpTransfer.BLL.RequestBLL.downloadFile(RequestDTO request, String path, FtpListItem ftpListItem, FtpClient ftpClient) in C:\SourceCode\Batch_FtpTransfer\Batch_FtpTransfer\Batch_FtpTransfer\BLL\RequestBLL.cs:line 51
at Program.Main(String[] args) in C:\SourceCode\Program.cs:line 71
解决方案
推荐阅读
- c# - .NET Core 2 中基于 JWT 的 API 授权:没有未经授权的错误
- python - Tensorflow 2.0 Keras 的训练速度比 2.0 Estimator 慢 4 倍
- stata - 浏览指令莫名其妙地阻塞了 URL
- java - 如何解决 Android Studio 中的“必须声明元素项目”问题?
- ruby-on-rails - Heroku 部署上的 Rails 配置失败
- c# - Web服务调用在线程中失败
- angular - Angular 7 反应形式有条件的“必需”验证
- ios - VNDetectRectanglesRequest 仅检测具有两个矩形的图像中的一个矩形 - Vision,Swift
- arrays - 提取路径内容/文件名组件 (BASH)
- .htaccess - 从 example.com/de/ 重定向到 example.com