Skip to content

SFTP DownloadFile hangs indefinitely when attempting to download moderate sized files  #733

Closed

Description

@zachmakki15

Hello,

I've been using SSH.NET for the past month for SFTP downloads and have been encountering an issue that I do not know how to work around. When calling the SftpClient DownloadFile method while attempting to download a file over about 100 KB the program will hang indefinitely even if the connection is forcibly closed by the remote host. This issue occurs inconsistently as sometimes I am able to download files without problem. After testing I have found this issue occurs with both the latest release available through NuGet and the 2020.0.0-beta1 release.

The code I am using to download files is listed below

foreach (string file in fileList)
{
    string filenameNoPath = file.Substring(file.LastIndexOf('/') + 1);
    string destination = outputPath + "\\" + filenameNoPath;
    using (Stream fileStream = File.OpenWrite(destination))
    {
        client.DownloadFile(file, fileStream);
        fileStream.Close();
    }
}

The platform I am using to test is Core SFTP Server (x64) installed on a Windows 10 Home machine. The connection between the testing platform and the client is my home LAN.

Activity

  1. zachmakki15 commented on Oct 14, 2020

    @zachmakki15
    Author

    After doing more research on this issue I found this link where someone else reports experiencing the same thing with SSH.NET and also shows testing done with other SSH clients https://forum.rebex.net/12973/sftp-file-downloads-hang-for-large-files. In one of the responses in the link someone mentions working around this issue by disables data transfer during SSH negotiation. Is anyone aware of how I might go about doing this?

  2. zachmakki15 commented on Oct 14, 2020

    @zachmakki15
    Author

    gavin1970 thank you for commenting, I am not very familiar with PSCP so I will have to look into it.

  3. gavin1970 commented on Oct 15, 2020

    @gavin1970

    Its part of the putty suite, however the suite isnt required. The developer of putty has it available for download from his website.

    https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

  4. zachmakki15 commented on Oct 15, 2020

    @zachmakki15
    Author

    I've looked into PSCP and unfortunately the company I work for does not allow us to use external executables like this, to add functionality to our project it has to be able to be added through NuGet or as a reference. Thank you for taking the time to make this recommendation though I really appreciate it.

  5. gavin1970 commented on Oct 15, 2020

    @gavin1970

    Putty is the recommended software for connecting to linux. Since PSCP is part of Putty and its open source, Im surprised your company doesn't allow it.

  6. k5123 commented on Jul 15, 2021

    @k5123
  7. k5123 commented on Jul 15, 2021

    @k5123

    Seeing similar behavior when downloading large (15gb) files. Download will hang intermittently for a while, then continue.

  8. gavin1970 commented on Jul 15, 2021

    @gavin1970

    Ever hear of a work around. Sometimes things don't work and we don't have time to fix someone else's issue. How does your reply help anyone or anything about this issue?

  9. zachmakki15 commented on Jul 15, 2021

    @zachmakki15
    Author

    k5123 have you tried to open a new issue? I never got a reply here from one of the SSH.NET developers and I believe I saw a few other issues pointing out similar problems.

  10. k5123 commented on Jul 15, 2021

    @k5123

    k5123 have you tried to open a new issue? I never got a reply here from one of the SSH.NET developers and I believe I saw a few other issues pointing out similar problems.

    Yeah probably a good idea. This issue was the one that came up on the search. But lets see if we can get a response with a new one.

  11. drieseng commented on Jul 15, 2021

    @drieseng
    Member

    Can anyone of you reproduce this issue consistently (and preferrably fast)? Can you reproduce this against a (non-production) server that I can access as well (public or privately)?

  12. k5123 commented on Jul 15, 2021

    @k5123

    Can anyone of you reproduce this issue consistently (and preferrably fast)? Can you reproduce this against a (non-production) server that I can access as well (public or privately)?

    I can, need to set up the SFTP endpoint though. Will take me a while. Sorry, my connection here (on vacation) keeps dropping, can't get this set up on short notice. However, any local sftpd + a large file will do.

  13. zachmakki15 commented on Jul 19, 2021

    @zachmakki15
    Author

    I have done some testing in the past few days using the latest release available thru NuGet and have been unable to reproduce this issue. Although I am testing with files much smaller then 15gb so the testing I did won't be very useful for k5123's issue. It does seem like the issue I was experiencing with moderately sized files has been fixed in the latest release. If I do run into this issue again I will comment here.

  14. k5123 commented on Aug 4, 2021

    @k5123

    Ok, i've tested things a bit more, and the issue seems to be a combination of two problems, one of which sits in SSH.NET. When comparing plain download performance (SftpClient::DownloadFile()) is dramatically slower when compared to the OpenSSH sftp client in Windows Server or Linux. We're talking 5 mins (openSSH) vs 30 mins (SSH.NET) on the same network link, same file.

    The other issue i observed - the intermittent freezes during download - appear to be related to PoSH-SSH, and i'm still looking into that one.

    Should i open a separate issue for the download performance?

  15. k5123 commented on Aug 4, 2021

    @k5123

    Update: I changed the capped buffer size from 65k to 256k, and was able to attain similar speeds as the OpenSSH sftp client. Is there a specific reason the size is hard capped to 65k in the current impl?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions