This utility class establishes a connection with an SSH server, determines which SSH protocol versions are supported and creates an initialized connection ready for authentication.
For a list of all members of this type, see SSHConnector Members.
System.Object
Maverick.SSH.SSHConnector
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
Each instance of this class maintains a set of configurations and settings for the connection of SSHClient's. The SSHContext interface describes the common options but there are many more options available for the individual protocols. If you want to set advanced options take a look at the SSH1Context and SSH2Context documentation.
To connect to an SSH server you need to provide an SSHTransport which provides the transport layer communication. In most cases this will be a Socket however this API is designed so that connections can be made through any communication medium supported by the platform providing that a suitable wrapper SSHTransport can be created. The TcpClientTransport class provides a suitable Socket implementation.
An instance of this class can be used to create as many client connections as required. There is no need to create a connector for every single client instance required. // Create a connection
SSHConnector con = SSHConnector.Create();
// Configure the connector before creating clients so that the same configuration
// can be used for multiple client instances
con.KnownHosts = new ConsoleKnownHostsKeyVerification();
// Create an SSH client
SSHClient ssh = con.Connect(new TcpClientTransport("my.domain.com, 22),
"root", true);
// Prepare the authentication request
PasswordAuthentication pwd = new PasswordAuthentication();
pwd.Password = "*********";
// Authenticate the user
if(ssh.Authenticate(pwd)==AuthenticationResult.COMPLETE)
{
// Open up a session and do something..
SSHSession session = ssh.OpenSessionChannel();
session.RequestPseudoTerminal("vt100", 80, 24, 0, 0);
session.ExecuteCommand("find / -name 'httpd.conf'");
// Do something with the returned data
System.IO.TextReader reader = new System.IO.StreamReader(session.GetStream());
String line;
while((line = reader.ReadLine()) != null)
System.Console.WriteLine(line);
session.Close():
}
ssh.Disconnect();
Namespace: Maverick.SSH
Assembly: Maverick.NET (in Maverick.NET.dll)
SSHConnector Members | Maverick.SSH Namespace