sshnet / sshnet/SSH.NET

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

Open
#225 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

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

        try
        {
            using (var client = new SftpClient(connectionInfo))
            {
                client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(10);

                client.Connect();

                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);
                    fs.Close();
                    returnState = true;
                }

                client.Disconnect();
                client.Dispose();
            }
        }

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. Am i missing something here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report centers on SftpClient, ConnectionInfo.Timeout, and DownloadFile; start by reproducing the network-cable interruption with a 10-second timeout and trace how connection recovery is handled. Search for the timeout and SFTP download implementation and related tests, then establish the expected behavior when connectivity returns before the timeout.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.