sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
http://sshnet.github.io/SSH.NET/
MIT License
3.98k stars 931 forks source link

Can't upload large file over SFTP (SshOperationTimeoutException) #103

Open apranovich opened 8 years ago

apranovich commented 8 years ago

For uploading .csv file over SFTP I use SSH.NET (version 2016.0.0).

The file which needs to be send is rather large (~7GB), and in about an hour after the uploading started it throws the exception Renci.SshNet.Common.SshOperationTimeoutException: Session operation has timed out.

Here is my actual uploading code.

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();
}

But this code works fine with smaller (tried with 1-4GB files) files than my desirable one (~7GB). I thought that it could depends on BufferSize, but playing with this property didn't fix the problem.

Here is the issue's stack trace.

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)

Also I've noticed that usually uploading throws the error in 1 hour after start and by that time it's uploaded ~80-90% of entire file (because I see not fully uploaded files in my destination SFTP folder).

Does someone has an idea why it's happening? Btw I've asked StackOverflow question regarding that: http://stackoverflow.com/questions/40158501/cant-upload-large-file-over-sftp Thanks in advance.

drieseng commented 8 years ago

Can I contact you offline to send you a debug version of SSH.NET with extra tracing? I dont't have the hardware to perform similar tests myself :(

apranovich commented 8 years ago

Yes, sure. Email: programmer.helps@gmail.com Skype: art-e-mka-

Johnny-Blue commented 7 years ago

Hi, I have the same issue with the timeout and my files are not even that big. It was all fine and it just stopped working a couple days ago. I connected to the remote SFTP site using FireFTP and it worked fine, but SSH.NET fails.

  Renci.SshNet.Common.SshOperationTimeoutException: Session operation has timed out
   at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
   at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle)
   at Renci.SshNet.Session.Connect()
   at Renci.SshNet.BaseClient.Connect()

Is there a solution for this?

I figured it out I think, not sure though what was the problem, but I'll put here my findings. Before yesterday, I was sending 1 or 2 files maximum. The code that actually connects to the sftp and uploads files was called for each particular file, so for each file I had a connect and a disconnect. Also, the SftpClient object was inside a using statement and probably tried to disconnect a second time when the scope of the using statement ended. Now I had to send about 12 files, all very small except one. It seems that the frequent connect/disconnect caused at some point the timeout exception above.

JSCProjects commented 7 years ago

@Johnny-Blue did you found a solution for your problem? I encounter this problem also.

jlareo commented 4 years ago

@drieseng I got the same error but in my case the file is less than 1mb

alabady commented 4 years ago

Find any solutions?

JSCProjects commented 4 years ago

Nope.

From: العبادي حسين notifications@github.com Sent: Wednesday, May 6, 2020 23:46 To: sshnet/SSH.NET SSH.NET@noreply.github.com Cc: JSC Projects mail@jsc-projects.nl; Comment comment@noreply.github.com Subject: Re: [sshnet/SSH.NET] Can't upload large file over SFTP (SshOperationTimeoutException) (#103)

Find any solutions?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/sshnet/SSH.NET/issues/103#issuecomment-624907802, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEVA2XPJ5BBYOGHPYGDM7WDRQHK73ANCNFSM4CTRDUFQ.