ssh2.channel
- class ssh2.channel.Channel
- close(self)
Close channel. Typically done to be able to get exit status.
- execute(self, command)
Execute command.
- Parameters:
command (str) – Command to execute
- Raises:
ssh2.exceptions.ChannelErroron errors executing command- Return type:
- flush(self)
Flush stdout stream
- flush_ex(self, int stream_id)
Flush stream with id
- flush_stderr(self)
Flush stderr stream
- get_exit_signal(self)
Get exit signal, message and language tag, if any, for command.
- Returns (returncode`,
exit signal,error message, language tag) tuple.
- Returns (returncode`,
- get_exit_status(self)
Get exit status of command.
Note that
0is also failure code for this function.Best used in non-blocking mode to avoid it being impossible to tell if
0indicates failure or an actual exit status of0.Exceptions are raised as with all functions in case of an SSH2Error.
- Return type:
- handle_extended_data(self, int ignore_mode)
Deprecated, use handle_extended_data2
- handle_extended_data2(self, int ignore_mode)
- ignore_extended_data(self, int ignore_mode)
Deprecated, use handle_extended_data2
- poll_channel_read(self, int extended)
Deprecated - use session.block_directions and socket polling instead
- process_startup(self, request, message=None)
Startup process on server for request with message.
Request is a supported SSH subsystem and clients would typically use one of execute/shell/subsystem functions depending on request type.
- Parameters:
request (str) – Request type (exec/shell/subsystem).
message (str or
None) – Request message. Content depends on request type and can beNone.
- pty(self, term='vt100')
Request a PTY (physical terminal emulation) on the channel.
- Parameters:
term (str) – Terminal type to emulate.
- read(self, size_t size=1024)
Read the stdout stream. Returns return code and output buffer tuple.
Return code is the size of the buffer when positive. Negative values are error codes.
- read_ex(self, size_t size=1024, int stream_id=0)
Read the stream with given id. Returns return code and output buffer tuple.
Return code is the size of the buffer when positive. Negative values are error codes.
- read_stderr(self, size_t size=1024)
Read the stderr stream. Returns return code and output buffer tuple.
Return code is the size of the buffer when positive. Negative values are error codes.
- receive_window_adjust(self, unsigned long adjustment, unsigned long force)
- receive_window_adjust2(self, unsigned long adjustment, unsigned long force)
- request_auth_agent(self)
Request SSH agent authentication forwarding on channel.
- send_eof(self)
Tell the remote host that no further data will be sent on the specified channel. Processes typically interpret this as a closed stdin descriptor.
Returns 0 on success or negative on failure. It returns
LIBSSH2_ERROR_EAGAINwhen it would otherwise block.- Return type:
- setenv(self, varname, value)
Set environment variable on channel.
- shell(self)
Request interactive shell from channel.
- Raises:
ssh2.exceptions.ChannelErroron errors requesting interactive shell.
- subsystem(self, subsystem)
Request subsystem from channel.
- Parameters:
subsystem (str) – Name of subsystem
- wait_closed(self)
Wait for server to acknowledge channel close command.
- wait_eof(self)
Wait for the remote end to acknowledge an EOF request.
Returns 0 on success or negative on failure. It returns
ssh2.error_codes.LIBSSH2_ERROR_EAGAINwhen it would otherwise block.- Return type:
- window_read(self)
- window_read_ex(self, unsigned long read_avail, unsigned long window_size_initial)
- window_write(self)
- window_write_ex(self, unsigned long window_size_initial)
- write(self, buf)
Write buffer to stdin.
Returns tuple of (
return_code,bytes_written).In blocking mode
bytes_writtenwill always equallen(buf)if no errors have occurred which would raise exception.In non-blocking mode
return_codecan be LIBSSH2_ERROR_EAGAIN andbytes_writtencan be less thanlen(buf).Clients should resume from that point on next call to
write, iebuf[bytes_written_in_last_call:].Note
While this function handles unicode strings for
bufargument,bytes_writtenoffset will always be for the bytes representation thereof as returned by the C function calls which only handle byte strings.
- write_ex(self, int stream_id, buf)
Write buffer to specified stream id.
Returns tuple of (
return_code,bytes_written).In blocking mode
bytes_writtenwill always equallen(buf)if no errors have occurred which would raise exception.In non-blocking mode
return_codecan be LIBSSH2_ERROR_EAGAIN andbytes_writtencan be less thanlen(buf).Clients should resume from that point on next call to the function, ie
buf[bytes_written_in_last_call:].Note
While this function handles unicode strings for
bufargument,bytes_writtenoffset will always be for the bytes representation thereof as returned by the C function calls which only handle byte strings.
- write_stderr(self, buf)
Write buffer to stderr.
Returns tuple of (
return_code,bytes_written).In blocking mode
bytes_writtenwill always equallen(buf)if no errors have occurred which would raise exception.In non-blocking mode
return_codecan be LIBSSH2_ERROR_EAGAIN andbytes_writtencan be less thanlen(buf).Clients should resume from that point on next call to
write, iebuf[bytes_written_in_last_call:].Note
While this function handles unicode strings for
bufargument,bytes_writtenoffset will always be for the bytes representation thereof as returned by the C function calls which only handle byte strings.
- x11_req(self, int screen_number)
- x11_req_ex(self, int single_connection, const char *auth_proto, const char *auth_cookie, int screen_number)
- session
Originating session.