Crash error while using SharpSSH

I am trying to connect to a Solaris/Unix server using the C# class to read system information / configuration, use memory, etc.

My requirement is to run commands on the server from a C # application ( as happens with the PuTTY client ), and save the response in a string variable for further processing.

After some research, I found that in order to do the same, you can use the SharpSSH library.

When I try to run my code, the following line gives me an Auth Fail exception . I am sure that the credentials (server name, username and password) are correct, since I can log in from the PuTTY client with the same credentials.

 SshStream ssh = new SshStream(servername, username, password); 

What am I doing wrong?

Below is a stack trace if that helps!

 at Tamir.SharpSsh.jsch.Session.connect(Int32 connectTimeout) at Tamir.SharpSsh.jsch.Session.connect() at Tamir.SharpSsh.SshStream..ctor(String host, String username, String password) 
+4
source share
1 answer

After some research, I found the VB code that pointed me in the right direction. It seems that adding an additional event handler for KeyboardInteractiveAuthenticationMethod helped solve this problem. Hope this helps someone else.

 void HandleKeyEvent(Object sender, AuthenticationPromptEventArgs e) { foreach (AuthenticationPrompt prompt in e.Prompts) { if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1) { prompt.Response = password; } } } private bool connectToServer() { try { KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(username); PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(username, password); kauth.AuthenticationPrompt += new EventHandler<AuthenticationPromptEventArgs>(HandleKeyEvent); ConnectionInfo connectionInfo = new ConnectionInfo(serverName, port, username, pauth, kauth); sshClient = new SshClient(connectionInfo); sshClient.Connect(); return true; } catch (Exception ex) { if (null != sshClient && sshClient.IsConnected) { sshClient.Disconnect(); } throw ex; } } 
+2
source

All Articles