无法通过SFTP上传大文件

时间:2016-10-20 15:22:09

标签: c# .net ssh sftp ssh.net

要通过SFTP上传.csv文件,请使用SSH.NET(版本2016.0.0)。

需要发送的文件相当大(~7GB),在上传开始后大约一个小时内抛出异常 Renci.SshNet.Common.SshOperationTimeoutException:会话操作超时

这是我的实际上传代码。

using (SftpClient client = new SftpClient(command.FtpHost, command.UserName, command.Password))
{
    client.Connect();
    client.ChangeDirectory(command.FtpTargetFolder);

    // played a lot with BufferSize property
    // tried to use the default value, tried 4*1024 and 8*1024
    client.BufferSize = 2 * 1024; 

    using (FileStream fileStream = new FileStream(command.LocalFilePath, FileMode.Open))
    {
        client.UploadFile(fileStream, PrepareFileName(command.LocalFilePath));
    }
    client.Disconnect();
}

但是这个代码适用于较小的(尝试使用1-4GB文件)文件而不是我想要的文件(~7GB)。我认为它可能取决于BufferSize,但使用此属性并没有解决问题。

这是问题的堆栈跟踪。

Renci.SshNet.Common.SshOperationTimeoutException: Session operation has timed out
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.Channels.Channel.GetDataLengthThatCanBeSentInMessage(Int32 messageLength)
at Renci.SshNet.Channels.Channel.SendData(Byte[] data, Int32 offset, Int32 size)
at Renci.SshNet.Sftp.SftpSession.SendRequest(SftpRequest request)
at Renci.SshNet.Sftp.SftpSession.RequestWrite(Byte[] handle, UInt64 offset, Byte[] data, Int32 length, AutoResetEvent wait, Action'1 writeCompleted)
at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action'1 uploadCallback)

另外我注意到通常上传会在启动后1小时内抛出错误,到那时它上传了大约80-90%的整个文件(因为我看不到目标SFTP文件夹中没有完全上传的文件)。

0 个答案:

没有答案
相关问题