SSH.NET TimeOut doesn't work above a certain time frame RRS feed

  • Question

  • I am using SSH.NET library to create sftp client. I need to resume the download if network connection becomes available again within this timeout. I am using the below mentioned approach as shown in many examples.

                PrivateKeyFile ObjPrivateKey = new PrivateKeyFile(keyStream);
                PrivateKeyAuthenticationMethod ObjPrivateKeyAutentication = new PrivateKeyAuthenticationMethod(username, ObjPrivateKey);
                var connectionInfo = new ConnectionInfo(hostAddress, port, username, ObjPrivateKeyAutentication);
                    using (var client = new SftpClient(connectionInfo))
                        client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(10);
                        if (!client.IsConnected)
                            return false;
                        if (!client.Exists(source))
                            return false;
                        var fileName = Path.GetFileName(source);
                        using (var fs = new FileStream(destination + fileName, FileMode.Create))
                            client.DownloadFile(source, fs, printActionDel);
                            returnState = true;

    I am unplugging the network cable to interrupt the download and test the timeout scenario. Though i enable the internet connection again within the timeout to resume the download, it is not resuming. What am i doing wrong here? Please advice.

    Tuesday, May 23, 2017 3:35 PM

All replies

  • Hi Rishanthan,

    Since SSH.NET is 3rd party library, I would suggest that you could post your issue on 3rd-party web site for suitable support.

    Thanks for your understanding.

    Best regards,

    Cole Wu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, May 24, 2017 3:10 AM
  • I've read the source for InternalDownloadFile() method and the underneath SftpFileReader and nothing in the source code indicates it supports automatic resume. Why do you expect it works this way?

    This library can support resume, but you must catch and handle the SshException (remember to check error message) and resume the download yourself.

    • Edited by cheong00 Wednesday, May 24, 2017 5:39 AM
    Wednesday, May 24, 2017 5:36 AM