System.Net.FtpClient.FtpCommandException:指定的网络名称不再可用

System.Net.FtpClient.FtpCommandException:指定的网络名称不再可用,ftp,ftp-client,Ftp,Ftp Client,下面的代码从FTP服务器获取文件并将其存储在本地 它适用于文件大小为1.8 GB的情况,引发System.Net.FtpClient.FtpCommandException:指定的网络名在1.99 GB左右时不再可用 var destinationPath = Path.Combine(path, ftpListItem.Name); ftpClient.ReadTimeout = 45000; ftpClient.SocketKeepAlive

下面的代码从FTP服务器获取文件并将其存储在本地

它适用于文件大小为1.8 GB的情况,引发System.Net.FtpClient.FtpCommandException:指定的网络名在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(缓冲区,0,计数)行引发异常

例外情况

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