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

Error code from the last operation (0 if connected and 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

Return

Array of strings (command output lines) or NULL if not connected.

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