ssh.open

Description

Open an SSH connection to a given host/port.

Syntax

ssh-conn = ssh.open(hostname[, port])

ParameterDescription
hostname String containing the name of the server to connect to.
port Number containing the server port to connect to (default is 22).

Return Value

Returns an ssh-conn connection object if successful. Any number returned likely indicates an error.

Remarks

None

Example

The following example demonstrates how to connect to a host and verify success.

if (typeof(conn=ssh.open("192.168.0.1", 22))!='ssh-conn') {
    print("failed connection");
    exit;
}
/* checking the host's RSA key fingerprint is optional, but a good idea. */
key="ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff";
if ((k=ssh.hostkey(conn))!=key) {
    print("expected = "+key+"\nrecieved = "+k+"\n");
    print("Host key verification failed.\n");
    exit;
}
print("RSA key fingerprint is "+k+".\n");
if (ssh.auth(conn, "username", "password")!=true) {
    print("failed auth");
    exit;
}
/*
 * do something useful here
 */

ssh.close(conn);