Go to the latest version of this document.
search in docstrings

Search bar offers the following options:

- Term presence. The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”: `+foo bar -baz`
- Wildcards. The below example searches for documents with words beginning with “foo”: `foo*`
- Search in specific fields. The following search matches all objects in "twisted.mail" that matches “search”: `+qname:twisted.mail.* +search`

  Possible fields: 'name', 'qname' (fully qualified name), 'docstring', and 'kind'. Last two fields are only applicable if "search in docstrings" is enabled.

- Fuzzy matches. The following search matches all documents that have a word within 1 edit distance of “foo”: `foo~1`

Results provided by Lunr.js

# ``twisted`.`conch`.`ssh`.`connection`.`SSHConnection``

class documentation

`class SSHConnection(service.SSHService): (source)`

Known subclasses: `twisted.conch.scripts.cftp.SSHConnection`, `twisted.conch.scripts.conch.SSHConnection`, `twisted.conch.scripts.tkconch.SSHConnection`, `twisted.conch.endpoints._ConnectionReady`

View In Hierarchy

An implementation of the 'ssh-connection' service. It is used to multiplex multiple channels over the single SSH connection.

Method | `__init__` | Undocumented
Method | `adjustWindow` | Tell the other side that we will receive more data. This should not normally need to be called as it is managed automatically.
Method | `channelClosed` | Called when a channel is closed. It clears the local state related to the channel, and calls channel.closed(). MAKE SURE YOU CALL THIS METHOD, even if you subclass `SSHConnection`. If you don't, things will break mysteriously.
Method | `getChannel` | The other side requested a channel of some sort. channelType is the type of channel being requested, windowSize is the initial size of the remote window, maxPacket is the largest packet we should send, data is any other packet data (often nothing).
Method | `gotGlobalRequest` | We got a global request. pretty much, this is just used by the client to request that we forward a port from the server to the client. Returns either:
Method | `openChannel` | Open a new channel on this connection.
Method | `sendClose` | Close a channel.
Method | `sendData` | Send data to a channel. This should not normally be used: instead use channel.write(data) as it manages the window automatically.
Method | `sendEOF` | Send an EOF (End of File) for a channel.
Method | `sendExtendedData` | Send extended data to a channel. This should not normally be used: instead use channel.writeExtendedData(data, dataType) as it manages the window automatically.
Method | `sendGlobalRequest` | Send a global request for this connection. Current this is only used for remote->local TCP forwarding.
Method | `sendRequest` | Send a request to a channel.
Method | `serviceStarted` | called when the service is active on the transport.
Method | `serviceStopped` | Called when the connection is stopped.
Method | `ssh_CHANNEL_CLOSE` | The other side is closing its end; it does not want to receive any more data. Payload:
Method | `ssh_CHANNEL_DATA` | The other side is sending us data. Payload:
Method | `ssh_CHANNEL_EOF` | The other side is not sending any more data. Payload:
Method | `ssh_CHANNEL_EXTENDED_DATA` | The other side is sending us exteneded data. Payload:
Method | `ssh_CHANNEL_FAILURE` | Our channel request to the other side failed. Payload:
Method | `ssh_CHANNEL_OPEN` | The other side wants to get a channel. Payload:
Method | `ssh_CHANNEL_OPEN_CONFIRMATION` | The other side accepted our MSG_CHANNEL_OPEN request. Payload:
Method | `ssh_CHANNEL_OPEN_FAILURE` | The other side did not accept our MSG_CHANNEL_OPEN request. Payload:
Method | `ssh_CHANNEL_REQUEST` | The other side is sending a request to a channel. Payload:
Method | `ssh_CHANNEL_SUCCESS` | Our channel request to the other side succeeded. Payload:
Method | `ssh_CHANNEL_WINDOW_ADJUST` | The other side is adding bytes to its window. Payload:
Method | `ssh_GLOBAL_REQUEST` | The other side has made a global request. Payload:
Method | `ssh_REQUEST_FAILURE` | Our global request failed. Get the appropriate Deferred and errback it with the packet we received.
Method | `ssh_REQUEST_SUCCESS` | Our global request succeeded. Get the appropriate Deferred and call it back with the packet we received.
Class Variable | `name` | Undocumented
Instance Variable | `channels` | a `dict` mapping a local channel ID to `SSHChannel` subclasses.
Instance Variable | `channelsToRemoteChannel` | a `dict` mapping a `SSHChannel` subclass to remote channel ID.
Instance Variable | `deferreds` | a `dict` mapping a local channel ID to a `list` of `Deferreds` for outstanding channel requests. Also, the 'global' key stores the `list` of pending global request `Deferred`s.
Instance Variable | `localChannelID` | the next number to use as a local channel ID.
Instance Variable | `localToRemoteChannel` | a `dict` mapping a local channel ID to a remote channel ID.
Instance Variable | `transport` | Undocumented
Method | `_cbChannelRequest` | Called back if the other side wanted a reply to a channel request. If the result is true, send a MSG_CHANNEL_SUCCESS. Otherwise, raise a `error.ConchError`
Method | `_cleanupGlobalDeferreds` | All pending requests that have returned a deferred must be errbacked when this service is stopped, otherwise they might be left uncalled and uncallable.
Method | `_ebChannelRequest` | Called if the other wisde wanted a reply to the channel requeset and the channel request failed.
Class Variable | `_log` | Undocumented

Inherited from `SSHService`:

Method | `logPrefix` | Undocumented
Method | `packetReceived` | called when we receive a packet on the transport
Class Variable | `protocolMessages` | Undocumented

def __init__(self): (source)
overridden in `twisted.conch.endpoints._ConnectionReady`

Undocumented

def adjustWindow(self, channel, bytesToAdd): (source)

Tell the other side that we will receive more data. This should not normally need to be called as it is managed automatically.

Parameters
channel:subclass of `SSHChannel` | Undocumented
bytesToAdd:`int` | Undocumented

def channelClosed(self, channel): (source)
overridden in `twisted.conch.scripts.conch.SSHConnection`

Called when a channel is closed. It clears the local state related to the channel, and calls channel.closed(). MAKE SURE YOU CALL THIS METHOD, even if you subclass `SSHConnection`. If you don't, things will break mysteriously.

Parameters
channel:`SSHChannel` | Undocumented

def getChannel(self, channelType, windowSize, maxPacket, data): (source)

The other side requested a channel of some sort. channelType is the type of channel being requested, windowSize is the initial size of the remote window, maxPacket is the largest packet we should send, data is any other packet data (often nothing).

We return a subclass of `SSHChannel`.

By default, this dispatches to a method 'channel_channelType' with any non-alphanumerics in the channelType replace with _'s. If it cannot find a suitable method, it returns an OPEN_UNKNOWN_CHANNEL_TYPE error. The method is called with arguments of windowSize, maxPacket, data.

Parameters
channelType:`bytes` | Undocumented
windowSize:`int` | Undocumented
maxPacket:`int` | Undocumented
data:`bytes` | Undocumented
Returns
subclass of `SSHChannel`/`tuple` | Undocumented

def gotGlobalRequest(self, requestType, data): (source)

We got a global request. pretty much, this is just used by the client to request that we forward a port from the server to the client. Returns either:

- 1: request accepted
- 1, <data>: request accepted with request specific data
- 0: request denied

By default, this dispatches to a method 'global_requestType' with -'s in requestType replaced with _'s. The found method is passed data. If this method cannot be found, this method returns 0. Otherwise, it returns the return value of that method.

Parameters
requestType:`bytes` | Undocumented
data:`bytes` | Undocumented
Returns
`int`/`tuple` | Undocumented

def openChannel(self, channel, extra=b''): (source)

Open a new channel on this connection.

Parameters
channel:subclass of `SSHChannel` | Undocumented
extra:`bytes` | Undocumented

def sendClose(self, channel): (source)

Close a channel.

Parameters
channel:subclass of `SSHChannel` | Undocumented

def sendData(self, channel, data): (source)

Send data to a channel. This should not normally be used: instead use channel.write(data) as it manages the window automatically.

Parameters
channel:subclass of `SSHChannel` | Undocumented
data:`bytes` | Undocumented

def sendEOF(self, channel): (source)

Send an EOF (End of File) for a channel.

Parameters
channel:subclass of `SSHChannel` | Undocumented

def sendExtendedData(self, channel, dataType, data): (source)

Send extended data to a channel. This should not normally be used: instead use channel.writeExtendedData(data, dataType) as it manages the window automatically.

Parameters
channel:subclass of `SSHChannel` | Undocumented
dataType:`int` | Undocumented
data:`bytes` | Undocumented

def sendGlobalRequest(self, request, data, wantReply=0): (source)

Send a global request for this connection. Current this is only used for remote->local TCP forwarding.

Parameters
request:`bytes` | Undocumented
data:`bytes` | Undocumented
wantReply:`bool` | Undocumented
Returns
`Deferred`/`None` | Undocumented

def sendRequest(self, channel, requestType, data, wantReply=0): (source)

Send a request to a channel.

Parameters
channel:subclass of `SSHChannel` | Undocumented
requestType:`bytes` | Undocumented
data:`bytes` | Undocumented
wantReply:`bool` | Undocumented
Returns
`Deferred`/`None` | Undocumented

def serviceStarted(self): (source)
overrides `twisted.conch.ssh.service.SSHService.serviceStarted`
overridden in `twisted.conch.scripts.cftp.SSHConnection`, `twisted.conch.scripts.conch.SSHConnection`, `twisted.conch.scripts.tkconch.SSHConnection`, `twisted.conch.endpoints._ConnectionReady`

called when the service is active on the transport.

def serviceStopped(self): (source)
overrides `twisted.conch.ssh.service.SSHService.serviceStopped`
overridden in `twisted.conch.scripts.conch.SSHConnection`

Called when the connection is stopped.

def ssh_CHANNEL_CLOSE(self, packet): (source)

The other side is closing its end; it does not want to receive any more data. Payload:

        uint32  local channel number

Notify the channnel by calling its closeReceived() method. If the channel has also sent a close message, call self.channelClosed().

def ssh_CHANNEL_DATA(self, packet): (source)

The other side is sending us data. Payload:

        uint32 local channel number
        string data

Check to make sure the other side hasn't sent too much data (more than what's in the window, or more than the maximum packet size). If they have, close the channel. Otherwise, decrease the available window and pass the data to the channel's dataReceived().

def ssh_CHANNEL_EOF(self, packet): (source)

The other side is not sending any more data. Payload:

        uint32  local channel number

Notify the channel by calling its eofReceived() method.

def ssh_CHANNEL_EXTENDED_DATA(self, packet): (source)

The other side is sending us exteneded data. Payload:

        uint32  local channel number
        uint32  type code
        string  data

Check to make sure the other side hasn't sent too much data (more than what's in the window, or than the maximum packet size). If they have, close the channel. Otherwise, decrease the available window and pass the data and type code to the channel's extReceived().

def ssh_CHANNEL_FAILURE(self, packet): (source)

Our channel request to the other side failed. Payload:

        uint32  local channel number

Get the `Deferred` out of self.deferreds and errback it with a `error.ConchError`.

def ssh_CHANNEL_OPEN(self, packet): (source)

The other side wants to get a channel. Payload:

        string  channel name
        uint32  remote channel number
        uint32  remote window size
        uint32  remote maximum packet size
        <channel specific data>

We get a channel from self.getChannel(), give it a local channel number and notify the other side. Then notify the channel by calling its channelOpen method.

def ssh_CHANNEL_OPEN_CONFIRMATION(self, packet): (source)

The other side accepted our MSG_CHANNEL_OPEN request. Payload:

        uint32  local channel number
        uint32  remote channel number
        uint32  remote window size
        uint32  remote maximum packet size
        <channel specific data>

Find the channel using the local channel number and notify its channelOpen method.

def ssh_CHANNEL_OPEN_FAILURE(self, packet): (source)

The other side did not accept our MSG_CHANNEL_OPEN request. Payload:

        uint32  local channel number
        uint32  reason code
        string  reason description

Find the channel using the local channel number and notify it by calling its openFailed() method.

def ssh_CHANNEL_REQUEST(self, packet): (source)

The other side is sending a request to a channel. Payload:

        uint32  local channel number
        string  request name
        bool    want reply
        <request specific data>

Pass the message to the channel's requestReceived method. If the other side wants a reply, add callbacks which will send the reply.

def ssh_CHANNEL_SUCCESS(self, packet): (source)

Our channel request to the other side succeeded. Payload:

        uint32  local channel number

Get the `Deferred` out of self.deferreds and call it back.

def ssh_CHANNEL_WINDOW_ADJUST(self, packet): (source)

The other side is adding bytes to its window. Payload:

        uint32  local channel number
        uint32  bytes to add

Call the channel's addWindowBytes() method to add new bytes to the remote window.

def ssh_GLOBAL_REQUEST(self, packet): (source)

The other side has made a global request. Payload:

        string  request type
        bool    want reply
        <request specific data>

This dispatches to self.gotGlobalRequest.

def ssh_REQUEST_FAILURE(self, packet): (source)

Our global request failed. Get the appropriate Deferred and errback it with the packet we received.

def ssh_REQUEST_SUCCESS(self, packet): (source)

Our global request succeeded. Get the appropriate Deferred and call it back with the packet we received.

name: `bytes` = (source)
overrides `twisted.conch.ssh.service.SSHService.name`

Undocumented

channels: `dict` = (source)

a `dict` mapping a local channel ID to `SSHChannel` subclasses.

channelsToRemoteChannel: `dict` = (source)

a `dict` mapping a `SSHChannel` subclass to remote channel ID.

deferreds: `dict[str, list]` = (source)

a `dict` mapping a local channel ID to a `list` of `Deferreds` for outstanding channel requests. Also, the 'global' key stores the `list` of pending global request `Deferred`s.

localChannelID: `int` = (source)

the next number to use as a local channel ID.

localToRemoteChannel: `dict` = (source)

a `dict` mapping a local channel ID to a remote channel ID.

transport = (source)
overrides `twisted.conch.ssh.service.SSHService.transport`

Undocumented

def _cbChannelRequest(self, result, localChannel): (source)

Called back if the other side wanted a reply to a channel request. If the result is true, send a MSG_CHANNEL_SUCCESS. Otherwise, raise a `error.ConchError`

Parameters
result:`bool` | the value returned from the channel's requestReceived() method. If it's False, the request failed.
localChannel:`int` | the local channel ID of the channel to which the request was made.
Raises
`ConchError` | if the result is False.

def _cleanupGlobalDeferreds(self): (source)

All pending requests that have returned a deferred must be errbacked when this service is stopped, otherwise they might be left uncalled and uncallable.

def _ebChannelRequest(self, result, localChannel): (source)

Called if the other wisde wanted a reply to the channel requeset and the channel request failed.

Parameters
result | a Failure, but it's not used.
localChannel:`int` | the local channel ID of the channel to which the request was made.

_log = (source)
overrides `twisted.conch.ssh.service.SSHService._log`

Undocumented