I am using Renci.ssh library in my .net console app to download content from secured FTP(SFTP). All I do is connect using SFTPClient of Renci.ssh library and download content and once the download is completed, I try to disconnect using same SFTPClient instance and application behaves bit strange. Sometimes it doesnt throw any error, at times it throws "Client not connected" or "Error while connecting to something that is not a Socket". I am clueless as to why app is behaving strangely.
Code:
try
{
ConnectionInfo conInfo = new PasswordConnectionInfo("********.com", username, password);
using (SftpClient client=new SftpClient(conInfo))
{
client.Connect();
Console.WriteLine("Connection before sleep: " + client.IsConnected);
Thread.Sleep(10 * 1000);
Console.WriteLine("Connection after sleep: " + client.IsConnected);
client.Disconnect();
}
}
catch (Exception ex)
{
}
StackTrace:
at System.Net.Sockets.Socket.Poll(Int32 microSeconds, SelectMode mode) at Renci.SshNet.Extensions.CanWrite(Socket socket) at Renci.SshNet.Session.SendMessage(Message message) at Renci.SshNet.Session.SendDisconnect(DisconnectReason reasonCode, String message) at Renci.SshNet.BaseClient.Disconnect() at TestSFTP.Program.Main(String[] args) in C:\Users*********\TestSFTP\TestSFTP\Program.cs:line 26