This project is read-only.

Session Time Out upon connecting using PrivateKey

Aug 16, 2012 at 5:15 PM
Edited Aug 16, 2012 at 5:21 PM

This is my first exposure to ssh.net.  It seems to offer everything that I am looking for however I cannot establish a connection.  I'm trying to connect to an sftp site which uses a private key, passphrase.  The connection just hangs and I'm receiving the following exception.

Renci.SshNet.Common.SshOperationTimeoutException: Session operation has timed ou
t
   at Renci.SshNet.Session.WaitHandle(WaitHandle waitHandle) in C:\Users\LP\Downloads\Renci.SshNet\Renci.SshNet\Session.cs:line 635
   at Renci.SshNet.Session.Connect() in C:\Users\LP\Downloads\Renci.SshNet
\Renci.SshNet\Session.cs:line 526
   at Renci.SshNet.BaseClient.Connect() in C:\Users\LP\Downloads\Renci.Ssh
Net\Renci.SshNet\BaseClient.cs:line 111
   at sshProject.Program.Main(String[] args) in C:\Users\LP\Documents\Visu
al Studio 2010\Projects\sshProject\sshProject\Program.cs:line 25

I'm using the following code to try and connect. 

 ConnectionInfo connectionInfo = new ConnectionInfo("192.168.1.31", 22, "lp_sftp", new PasswordAuthenticationMethod("lp_sftp", "Password123"), new PrivateKeyAuthenticationMethod("lp_sftp", new PrivateKeyFile(File.OpenRead(@"C:\LP_SFTP_TESTING_KEY_20120622.pem"), "Password123")));
            using (SftpClient sftp = new SftpClient(connectionInfo))
            {
                try
                {
                    sftp.OperationTimeout = new TimeSpan(0, 0, 30);                   
                    sftp.Connect();
                }
                catch (Exception exe)
                {
                    Console.WriteLine(exe.ToString());
                }
                if (sftp.IsConnected)
                {
                    Console.WriteLine("Connected");
                    var ls = sftp.ListDirectory(".");
                    foreach (var s in ls)
                    {
                        Console.WriteLine(s);
                    }
                }
                else
                    Console.Write("Not Connected");
            }
            Console.Read();

Does anyone have any ideas as to why this would be happening?

I did a little digging and it appears to display an error upon the following line of code.

//  Wait for key exchange to be completed
    this.WaitHandle(this._keyExchangeCompletedWaitHandle);

Line 526 of the Session.cs class.

Sep 5, 2012 at 6:41 AM

Even i am facing the same issue