SSH.NET icon indicating copy to clipboard operation
SSH.NET copied to clipboard

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

Open Rishanthakumar opened this issue 9 years ago • 0 comments

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.

Rishanthakumar avatar May 23 '17 15:05 Rishanthakumar