SSH Connection API - TJohn2017/Laputa GitHub Wiki

The SSHConnection class provides the core SSH functionality necessary to establish, authenticate, write to, resize a terminal for, and disconnect from SSH connections. One connection should be created and managed for each desired connection (i.e. one per terminal view, even if they are for the same host). The file is found at: SSHConnection.swift

connect

Behavior

Connect accepts an object populated with connection data and attempts to establish that connection. It creates the initial connection, authorizes (if necessary), and requests an Xterm pseudo-terminal (Xterm is the robust emulation format used by SwiftTerm).

Parameters

hostInfo: HostInfo (A populated object containing host and authorization data)

Returns

void

throws

  • SSHSessionError.authorizationFailed (The connection was established but failed to authorize)
  • SSHSessionError.connectFailed (The initial connection failed to be made)

disconnect

Behavior

Closes the open shell and disconnects from the host.

Parameters

None

Returns

void

throws

None

executeCommand

Behavior

Accepts a command with arguments to be executed over the open connection. The result of this command is waited for and returned to the user. Note: this command is incompatible with the pseudo-terminal format used to power the terminals, and thus is currently unused.

Parameters

command: String (The command to be executed)

Returns

String: the result output of the command.

throws

None

write

Behavior

Accepts an array slice of data in bytes to be written over the current connection's pseudo-terminal. This is done by converting the provided data to a string and writing that string in its entirety to the ssh connection. If successful nothing is returned, but throws on error.

Parameters

data: ArraySlice (The data to be written in an array of UInt8's (bytes))

Returns

void

throws

NMSSHChannelWriteError (populated with more detailed error objects by NMSSH)

requestTerminalSize

Behavior

Requests a new terminal size from the host connection in characters wide and high, returning the success state of the request as a boolean value.

Parameters

  • width: UInt (The desired terminal width in characters)
  • height: UInt (The desired terminal height in characters)

Returns

Bool (True on success and false on failure)

throws

None

isConnected

Behavior

Returns true if a session is currently connected or false if it is not.

Parameters

None

Returns

Bool (Whether or not there is an open connection)

throws

None

⚠️ **GitHub.com Fallback** ⚠️