Implements interfaces: twisted.internet.interfaces.IStreamClientEndpoint

SSHCommandClientEndpoint exposes the command-executing functionality of SSH servers.

SSHCommandClientEndpoint can set up a new SSH connection, authenticate it in any one of a number of different ways (keys, passwords, agents), launch a command over that connection and then associate its input and output with a protocol.

It can also re-use an existing, already-authenticated SSH connection (perhaps one which already has some SSH channels being used for other purposes). In this case it creates a new SSH channel to use to execute the command. Notably this means it supports multiplexing several different command invocations over a single SSH connection.

Method __init__ No summary
Class Method newConnection No summary
Class Method existingConnection No summary
Method connect Set up an SSH connection, use a channel from that connection to launch a command, and hook the stdin and stdout of that command up as a transport for a protocol created by the given factory.
Method _executeCommand Given a secured SSH connection, try to execute a command in a new channel created on it and associate the result with a protocol from the given factory.
def __init__(self, creator, command): (source)
ParameterscreatorAn _ISSHConnectionCreator provider which will be used to set up the SSH connection which will be used to run a command. (type: _ISSHConnectionCreator provider)
commandThe command line to execute on the SSH server. This byte string is interpreted by a shell on the SSH server, so it may have a value like "ls /". Take care when trying to run a command like "/Volumes/My Stuff/a-program" - spaces (and other special bytes) may require escaping. (type: bytes)
@classmethod
def newConnection(cls, reactor, command, username, hostname, port=None, keys=None, password=None, agentEndpoint=None, knownHosts=None, ui=None): (source)

Create and return a new endpoint which will try to create a new connection to an SSH server and run a command over it. It will also close the connection if there are problems leading up to the command being executed, after the command finishes, or if the connection Deferred is cancelled.

ParametersreactorThe reactor to use to establish the connection. (type: IReactorTCP provider)
commandSee __init__'s command argument.
usernameThe username with which to authenticate to the SSH server. (type: bytes)
hostnameThe hostname of the SSH server. (type: bytes)
portThe port number of the SSH server. By default, the standard SSH port number is used. (type: int)
keysPrivate keys with which to authenticate to the SSH server, if key authentication is to be attempted (otherwise None). (type: list of Key)
passwordThe password with which to authenticate to the SSH server, if password authentication is to be attempted (otherwise None). (type: bytes or None)
agentEndpointAn IStreamClientEndpoint provider which may be used to connect to an SSH agent, if one is to be used to help with authentication. (type: IStreamClientEndpoint provider)
knownHostsThe currently known host keys, used to check the host key presented by the server we actually connect to. (type: KnownHostsFile)
uiAn object for interacting with users to make decisions about whether to accept the server host keys. If None, a ConsoleUI connected to /dev/tty will be used; if /dev/tty is unavailable, an object which answers b"no" to all prompts will be used. (type: None or ConsoleUI)
ReturnsA new instance of cls (probably SSHCommandClientEndpoint).
@classmethod
def existingConnection(cls, connection, command): (source)

Create and return a new endpoint which will try to open a new channel on an existing SSH connection and run a command over it. It will not close the connection if there is a problem executing the command or after the command finishes.

ParametersconnectionAn existing connection to an SSH server. (type: SSHConnection)
commandSee SSHCommandClientEndpoint.newConnection's command parameter. (type: bytes)
ReturnsA new instance of cls (probably SSHCommandClientEndpoint).
def connect(self, protocolFactory): (source)

Set up an SSH connection, use a channel from that connection to launch a command, and hook the stdin and stdout of that command up as a transport for a protocol created by the given factory.

ParametersprotocolFactoryA Factory to use to create the protocol which will be connected to the stdin and stdout of the command on the SSH server.
ReturnsA Deferred which will fire with an error if the connection cannot be set up for any reason or with the protocol instance created by protocolFactory once it has been connected to the command.
def _executeCommand(self, connection, protocolFactory): (source)

Given a secured SSH connection, try to execute a command in a new channel created on it and associate the result with a protocol from the given factory.

ParametersconnectionSee SSHCommandClientEndpoint.existingConnection's connection parameter.
protocolFactorySee SSHCommandClientEndpoint.connect's protocolFactory parameter.
ReturnsSee SSHCommandClientEndpoint.connect's return value.
API Documentation for Twisted, generated by pydoctor at 2018-10-15 19:29:43.