Home | Trees | Indices | Help |
---|
|
object --+ | Channel
A secure tunnel across an SSH Transport. A Channel is meant to behave like a socket, and has an API that should be indistinguishable from the python socket API.
Because SSH2 has a windowing kind of flow control, if you stop reading data from a Channel and its buffer fills up, the server will be unable to send you any more data until you read some of it. (This won't affect other channels on the same transport -- all channels on a single transport are flow-controlled independently.) Similarly, if the server isn't reading data you send, calls to send may block, unless you set a timeout. This is exactly like a normal network socket, so it shouldn't be too surprising.
Instance Methods | |||
|
|||
|
|||
str |
|
||
|
|||
|
|||
bool |
|
||
int |
|
||
int |
|
||
str |
|
||
|
|||
Transport |
|
||
tuple(str, int) |
|
||
float |
|
||
|
|||
|
|||
ChannelFile |
|
||
ChannelFile |
|
||
str |
|
||
int |
|
||
boolean |
|
||
str |
|
||
boolean |
|
||
|
|||
|
|||
int |
|
||
|
|||
boolean |
|
||
int |
|
||
|
|||
|
|||
bool |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from |
Properties | |
Inherited from |
Method Details |
Create a new channel. The channel is not associated with any particular session or Transport until the Transport attaches it. Normally you would only call this method from the constructor of a subclass of Channel.
|
Return a string representation of this object, for debugging.
|
Close the channel. All future read/write operations on the channel will fail. The remote end will receive no more data (after queued data is flushed). Channels are automatically closed when their Transport is closed or when they are garbage collected. |
Execute a command on the server. If the server allows it, the channel will then be directly connected to the stdin, stdout, and stderr of the command being executed. When the command finishes executing, the channel will be closed and can't be reused. You must open a new channel if you wish to execute another command.
|
Return true if the remote process has exited and returned an exit status. You may use this to poll the process status if you don't want to block in recv_exit_status. Note that the server may not return an exit status in some cases (like bad servers).
Since: 1.7.3 |
Returns an OS-level file descriptor which can be used for polling, but
but not for reading or writing. This is primaily to allow
python's The first time
Warning: This method causes channel reads to be slightly less efficient. |
Return the ID # for this channel. The channel ID is unique across a Transport and usually a small number. It's also the number passed to ServerInterface.check_channel_request when determining whether to accept a channel request in server mode.
|
Get the name of this channel that was previously set by set_name.
|
Request a pseudo-terminal from the server. This is usually used right after creating a client channel, to ask the server to provide some basic terminal semantics for a shell invoked with invoke_shell. It isn't necessary (or desirable) to call this method if you're going to exectue a single command with exec_command.
|
Return the Transport associated with this channel. |
Return the address of the remote side of this Channel, if possible.
This is just a wrapper around
|
Returns the timeout in seconds (as a float) associated with socket
operations, or
|
Request an interactive shell session on this channel. If the server allows it, the channel will then be directly connected to the stdin, stdout, and stderr of the shell. Normally you would call get_pty before this, in which case the shell will operate through the pty, and the channel will be connected to the stdin and stdout of the pty. When the shell exits, the channel will be closed and can't be reused. You must open a new channel if you wish to open another shell.
|
Request a subsystem on the server (for example, When the subsystem finishes, the channel will be closed and can't be reused.
|
Return a file-like object associated with this channel. The optional
|
Return a file-like object associated with this channel's stderr stream. Only channels using exec_command or invoke_shell without a pty will ever have data on the stderr stream. The optional
Since: 1.1 |
Receive data from the channel. The return value is a string
representing the data received. The maximum amount of data to be
received at once is specified by
|
Return the exit status from the process on the server. This is mostly useful for retrieving the reults of an exec_command. If the command hasn't finished yet, this method will wait until it does, or until the channel is closed. If no exit status is provided by the server, -1 is returned.
Since: 1.2 |
Returns true if data is buffered and ready to be read from this
channel. A
|
Receive data from the channel's stderr stream. Only channels using exec_command or invoke_shell without a pty will ever have data on the
stderr stream. The return value is a string representing the data
received. The maximum amount of data to be received at once is specified
by
Since: 1.1 |
Returns true if data is buffered and ready to be read from this channel's stderr stream. Only channels using exec_command or invoke_shell without a pty will ever have data on the stderr stream.
Since: 1.1 |
Request an x11 session on this channel. If the server allows it, further x11 requests can be made from the server to the client, when an x11 application is run in a shell session. From RFC4254: It is RECOMMENDED that the 'x11 authentication cookie' that is sent be a fake, random cookie, and that the cookie be checked and replaced by the real cookie when a connection request is received. If you omit the auth_cookie, a new secure random 128-bit value will be generated, used, and returned. You will need to use this value to verify incoming x11 requests and replace them with the actual local x11 cookie (which requires some knoweldge of the x11 protocol). If a handler is passed in, the handler is called from another thread whenever a new x11 connection arrives. The default handler queues up incoming x11 connections, which may be retrieved using Transport.accept. The handler's calling signature is: handler(channel: Channel, (address: str, port: int))
|
Resize the pseudo-terminal. This can be used to change the width and height of the terminal emulation created in a previous get_pty call.
|
Send data to the channel. Returns the number of bytes sent, or 0 if the channel stream is closed. Applications are responsible for checking that all data has been sent: if only some of the data was transmitted, the application needs to attempt delivery of the remaining data.
|
Send the exit status of an executed command to the client. (This really only makes sense in server mode.) Many clients expect to get some sort of status code back from an executed command after it completes.
Since: 1.2 |
Returns true if data can be written to this channel without blocking. This means the channel is either closed (so any write attempt would return immediately) or there is at least one byte of space in the outbound buffer. If there is at least one byte of space in the outbound buffer, a send call will succeed immediately and return the number of bytes actually written.
|
Send data to the channel on the "stderr" stream. This is normally only used by servers to send output from shell commands -- clients won't use this. Returns the number of bytes sent, or 0 if the channel stream is closed. Applications are responsible for checking that all data has been sent: if only some of the data was transmitted, the application needs to attempt delivery of the remaining data.
Since: 1.1 |
Send data to the channel, without allowing partial results. Unlike send, this method continues to send data from the given string until either all data has been sent or an error occurs. Nothing is returned.
Note: If the channel is closed while only part of the data hase been sent, there is no way to determine how much data (if any) was sent. This is irritating, but identically follows python's API. |
Send data to the channel's "stderr" stream, without allowing partial results. Unlike send_stderr, this method continues to send data from the given string until all data has been sent or an error occurs. Nothing is returned.
Since: 1.1 |
Set whether stderr should be combined into stdout on this channel. The
default is If this is If this is
Since: 1.1 |
Set a name for this channel. Currently it's only used to set the name of the channel in logfile entries. The name can be fetched with the get_name method.
|
Set blocking or non-blocking mode of the channel: if
In non-blocking mode, if a recv call doesn't find any data, or if a send call can't immediately dispose of the data, an error exception is raised. In blocking mode, the calls block until they can proceed. An EOF condition is considered "immediate data" for recv, so if the channel is closed in the read direction, it will never block.
|
Set a timeout on blocking read/write operations. The
|
Shut down one or both halves of the connection. If
|
Shutdown the receiving side of this socket, closing the stream in the
incoming direction. After this call, future reads on this channel will
fail instantly. This is a convenience method, equivalent to
Since: 1.2 |
Shutdown the sending side of this socket, closing the stream in the
outgoing direction. After this call, future writes on this channel will
fail instantly. This is a convenience method, equivalent to
Since: 1.2 |
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon May 23 13:50:03 2011 | http://epydoc.sourceforge.net |