Package libssh2 :: Module session :: Class Session

[frames] | no frames]

# Class Session

source code

    object --+
             |
            Session

Session object

Instance Methods

__init__(self) Create a new session object. | source code

callback_set(self, callback_type, callback) Sets callback on the session. | source code

int

close(self, reason="Disconnect") Closes the session. | source code

Channel

direct_tcpip(self, host, port, shost, sport) Tunnels a TCP connection through the session. | source code

`Listener`

forward_listen(self, host, port, bound_port, queue_maxsize) Forwards a TCP connection through the session. | source code

str

hostkey_hash(self, hashtype) Returns the computed digest of the remote host's key. | source code

tuple

last_error(self) Returns the last error in tuple format (code, message). | source code

Channel

open_session(self) Allocates a new Channel for the session. | source code

set_trace(self, bitmask) Sets trace level on the session. | source code

Channel

scp_recv(self, remote_path) Gets a remote file via SCP Protocol. | source code

Channel

scp_send(self, path, mode, size) Sends a file to remote host via SCP protocol. | source code

int

session_method_pref(self, method_type, pref) Sets preferred methods to be negociated. | source code

dict

session_methods(self) Returns dictionnary with the current actives algorithms. | source code

int

set_banner(self, banner=_libssh2.DEFAULT_BANNER) Sets the banner that will be sent to remote host. | source code

Sftp

sftp_init(self) Open an Sftp Channel. | source code

int

startup(self, sock) Starts up the session form a socket created by a socket.socket() call. | source code

int

userauth_authenticated(self) Returns authentification status for the given session. | source code

str

userauth_list(self, username) Lists the authentification methods supported by a server. | source code

int

userauth_password(self, username, password) Authenticates a session with the given username and password. | source code

int

userauth_publickey_fromfile(self, username, publickey, privatekey, passphrase) Authenticates a session as username using a key pair found in the pulickey and privatekey files, and passphrase if provided. | source code

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self)
(Constructor)

source code

Create a new session object.

Overrides: object.__init__

### callback_set(self, callback_type, callback)

source code

Sets callback on the session.

Parameters:
  - `callback_type` - value of libssh2.LIBSSH2_CALLBACK_* constant
  - `callback` (function) - a callback Python object
  - `callback_set` (int)

### close(self, reason="Disconnect")

source code

Closes the session.

Parameters:
  - `reason` (str) - human readable reason for disconnection
Returns: int
  0 on success or negative on failure

### direct_tcpip(self, host, port, shost, sport)

source code

Tunnels a TCP connection through the session.

Parameters:
  - `host` (str) - remote host
  - `port` (int) - remote port
  - `shost` (str) - local host
  - `sport` (int) - local port
Returns: Channel
  new opened Channel

### forward_listen(self, host, port, bound_port, queue_maxsize)

source code

Forwards a TCP connection through the session.

Parameters:
  - `host` (str) - remote host
  - `port` (int) - remote port
  - `bound_port` (int) - populated with the actual port on the remote host
  - `queue_maxsize` - maxium number of pending connections @type int
Returns: `Listener`
  new `Listener` instance on success or None on failure

### hostkey_hash(self, hashtype)

source code

Returns the computed digest of the remote host's key.

Parameters:
  - `hashtype` (int) - values possible are 1 (HASH_MD5) or 2 (HASH_SHA1)
Returns: str
  string representation of the computed hash value

### last_error(self)

source code

Returns the last error in tuple format (code, message).

Returns: tuple
  error tuple (int, str)

### open_session(self)

source code

Allocates a new Channel for the session.

Returns: Channel
  new channel opened

### set_trace(self, bitmask)

source code

Sets trace level on the session.

Parameters:
  - `bitmask` - bitmask on libssh2.LIBSSH2_TRACE_* constant

### scp_recv(self, remote_path)

source code

Gets a remote file via SCP Protocol.

Parameters:
  - `remote_path` (str) - absolute path of remote file to transfer
Returns: Channel
  new channel opened

### scp_send(self, path, mode, size)

source code

Sends a file to remote host via SCP protocol.

Parameters:
  - `path` (str) - absolute path of file to transfer
  - `mode` (int) - file access mode to create file
  - `size` (int) - size of file being transmitted
Returns: Channel
  new channel opened

### session_method_pref(self, method_type, pref)

source code

Sets preferred methods to be negociated. Theses preferences must be prior to calling startup.

Parameters:
  - `method_type` (int) - the method type constants
  - `pref` (str) - coma delimited list of preferred methods
Returns: int
  0 on success or negative on failure

### session_methods(self)

source code

Returns dictionnary with the current actives algorithms. CS keys is Client to Server and SC keys is Server to Client.

Returns: dict
  dictionnary with actual method negociated

### set_banner(self, banner=_libssh2.DEFAULT_BANNER)

source code

Sets the banner that will be sent to remote host. This is optional, the banner `_libssh2.DEFAULT_BANNER` will be sent by default.

Parameters:
  - `banner` (str) - an user defined banner
Returns: int
  0 on success or negative on failure

### sftp_init(self)

source code

Open an Sftp Channel.

Returns: Sftp
  new Sftp channel opened

### startup(self, sock)

source code

Starts up the session form a socket created by a socket.socket() call.

Parameters:
  - `sock` (socket._socketobject) - a connected socket object
Returns: int
  0 on success or negative on failure

### userauth_authenticated(self)

source code

Returns authentification status for the given session.

Returns: int
  non-zero if authenticated or 0 if not

### userauth_list(self, username)

source code

Lists the authentification methods supported by a server.

Parameters:
  - `username` (str) - username which will be used while authenticating
Returns: str
  string containing a comma-separated list of authentication methods

### userauth_password(self, username, password)

source code

Authenticates a session with the given username and password.

Parameters:
  - `username` (str) - user to authenticate
  - `password` (str) - password to use for the authentication
Returns: int
  0 on success or negative on failure

### userauth_publickey_fromfile(self, username, publickey, privatekey, passphrase)

source code

Authenticates a session as username using a key pair found in the pulickey and privatekey files, and passphrase if provided.

Parameters:
  - `username` (str) - user to authenticate
  - `publickey` (str) - path and name of public key file
  - `privatekey` (str) - path and name of private key file
  - `passphrase` (str) - passphrase to use when decoding private file
Returns: int
  0 on success or negative on failure