SSHSession

Represents an interactive SSH session to a remote node for executing commands and managing privilege escalation. SSHSession objects are typically created through the Node class method openSSHSession().

Instance attributes

connected: bool

Returns TRUE if the SSH channel is connected.

lastError: int

Agent error code from the last operation (0 if there was no error).

lastErrorMessage: String

Text description of the last error.

nodeId: int

ID of the node this session is connected to.

privileged: bool

Returns TRUE if the session has escalated privileges.

Instance methods

close(): void

Close the SSH session.

session = $node->openSSHSession();
if (session->connected) {
    // Execute commands...
    session->close();
}
escalatePrivilege(password): bool

Escalate to privileged user.

Table 1. Parameters

password

String

Password for privilege escalation

Return

TRUE if successful, FALSE otherwise.

session = $node->openSSHSession();
if (session->connected) {
    if (session->escalatePrivilege("secretpassword")) {
        // Execute privileged commands...
    }
}
execute(command, timeout): Array

Execute a command on the remote host.

Table 2. Parameters

command

String

Command to execute

timeout

Integer

Optional timeout in milliseconds. If omitted or 0, the default command timeout for the device type is used (30 seconds unless the SSH driver sets another value).

Return

Array of strings (command output lines), or null if the session is not connected or the command failed or timed out (see lastError). Every executed command is recorded in the audit log.

session = $node->openSSHSession();
if (session->connected) {
    output = session->execute("ls -la", 5000);
    for (line : output) {
        println(line);
    }
    session->close();
}