Package paramiko :: Module auth_transport :: Class Transport
[show private | hide private]
[frames | no frames]

Class Transport

object --+            
         |            
  _Verbose --+        
             |        
        Thread --+    
                 |    
     BaseTransport --+
                     |
                    Transport


An SSH Transport attaches to a stream (usually a socket), negotiates an encrypted session, authenticates, and then creates stream tunnels, called Channels, across the session. Multiple channels can be multiplexed across a single session (and often are, in the case of port forwardings).
Method Summary
  __init__(self, sock)
Create a new SSH session over an existing socket, or socket-like object.
str __repr__(self)
Returns a string representation of this object, for debugging.
list auth_password(self, username, password, event)
Authenticate to the server using a password.
list auth_publickey(self, username, key, event)
Authenticate to the server using a private key.
string get_username(self)
Return the username this connection is authenticated for.
bool is_authenticated(self)
Return true if this session is active and authenticated.
    Inherited from BaseTransport
  accept(self, timeout)
  add_server_key(self, key)
Add a host key to the list of keys used for server mode.
  close(self)
Close this session, and any open channels that are tied to it.
  connect(self, hostkey, username, password, pkey)
Negotiate an SSH2 session, and optionally verify the server's host key and authenticate using a password or private key.
Exception get_exception(self)
Return any exception that happened during the last server request.
bool get_hexdump(self)
Return True if the transport is currently logging hex dumps of protocol traffic.
str get_log_channel(self)
Return the channel name used for this transport's logging.
PKey get_remote_server_key(self)
Return the host key of the server (in client mode).
SecurityOptions get_security_options(self)
Return a SecurityOptions object which can be used to tweak the encryption algorithms this transport will permit, and the order of preference for them.
PKey get_server_key(self)
Return the active host key, in server mode.
Message global_request(self, kind, data, wait)
Make a global request to the remote host.
bool is_active(self)
Return true if this session is active (open).
bool load_server_moduli(filename)
(optional) Load a file of prime moduli for use in doing group-exchange key negotiation in server mode. (Static method)
Channel open_channel(self, kind, dest_addr, src_addr)
Request a new channel to the server.
Channel open_session(self)
Request a new channel to the server, of type "session".
SFTPClient open_sftp_client(self)
Create an SFTP client channel from an open transport.
bool renegotiate_keys(self)
Force this session to switch to new keys.
  send_ignore(self, bytes)
Send a junk packet across the encrypted link.
  set_hexdump(self, hexdump)
Turn on/off logging a hex dump of protocol traffic at DEBUG level in the logs.
  set_keepalive(self, interval)
Turn on/off keepalive packets (default is off).
  set_log_channel(self, name)
Set the channel for this transport's logging.
  set_subsystem_handler(self, name, handler, *larg, **kwarg)
Set the handler class for a subsystem in server mode.
  start_client(self, event)
Negotiate a new SSH2 session as a client.
  start_server(self, event, server)
Negotiate a new SSH2 session as a server.
  stop_thread(self)
    Inherited from Thread
  getName(self)
  isAlive(self)
  isDaemon(self)
  join(self, timeout)
  run(self)
  setDaemon(self, daemonic)
  setName(self, name)
  start(self)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)
    Inherited from type
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T

Instance Method Details

__init__(self, sock)
(Constructor)

Create a new SSH session over an existing socket, or socket-like object. This only creates the Transport object; it doesn't begin the SSH session yet. Use connect or start_client to begin a client session, or start_server to begin a server session.

If the object is not actually a socket, it must have the following methods:
  • send(str): Writes from 1 to len(str) bytes, and returns an int representing the number of bytes written. Returns 0 or raises EOFError if the stream has been closed.
  • recv(int): Reads from 1 to int bytes and returns them as a string. Returns 0 or raises EOFError if the stream has been closed.
  • close(): Closes the socket.
  • settimeout(n): Sets a (float) timeout on I/O operations.
For ease of use, you may also pass in an address (as a tuple) or a host string as the sock argument. (A host string is a hostname with an optional port (separated by ":") which will be converted into a tuple of (hostname, port).) A socket will be connected to this address and used for communication. Exceptions from the socket call may be thrown in this case.
Parameters:
sock - a socket or socket-like object to create the session over.
           (type=socket)
Overrides:
paramiko.transport.BaseTransport.__init__ (inherited documentation)

__repr__(self)
(Representation operator)

Returns a string representation of this object, for debugging.
Returns:
str
Overrides:
paramiko.transport.BaseTransport.__repr__ (inherited documentation)

auth_password(self, username, password, event=None)

Authenticate to the server using a password. The username and password are sent over an encrypted link.

If an event is passed in, this method will return immediately, and the event will be triggered once authentication succeeds or fails. On success, is_authenticated will return True. On failure, you may use get_exception to get more detailed error information.

Since 1.1, if no event is passed, this method will block until the authentication succeeds or fails. On failure, an exception is raised. Otherwise, the method simply returns.

If the server requires multi-step authentication (which is very rare), this method will return a list of auth types permissible for the next step. Otherwise, in the normal case, an empty list is returned.
Parameters:
username - the username to authenticate as
           (type=string)
password - the password to authenticate with
           (type=string)
event - an event to trigger when the authentication attempt is complete (whether it was successful or not)
           (type=threading.Event)
Returns:
list of auth types permissible for the next stage of authentication (normally empty)
           (type=list)
Raises:
BadAuthenticationType - if password authentication isn't allowed by the server for this user (and no event was passed in)
SSHException - if the authentication failed (and no event was passed in)

auth_publickey(self, username, key, event=None)

Authenticate to the server using a private key. The key is used to sign data from the server, so it must include the private part.

If an event is passed in, this method will return immediately, and the event will be triggered once authentication succeeds or fails. On success, is_authenticated will return True. On failure, you may use get_exception to get more detailed error information.

Since 1.1, if no event is passed, this method will block until the authentication succeeds or fails. On failure, an exception is raised. Otherwise, the method simply returns.

If the server requires multi-step authentication (which is very rare), this method will return a list of auth types permissible for the next step. Otherwise, in the normal case, an empty list is returned.
Parameters:
username - the username to authenticate as.
           (type=string)
key - the private key to authenticate with.
           (type=PKey)
event - an event to trigger when the authentication attempt is complete (whether it was successful or not)
           (type=threading.Event)
Returns:
list of auth types permissible for the next stage of authentication (normally empty).
           (type=list)
Raises:
BadAuthenticationType - if public-key authentication isn't allowed by the server for this user (and no event was passed in).
SSHException - if the authentication failed (and no event was passed in).

get_username(self)

Return the username this connection is authenticated for. If the session is not authenticated (or authentication failed), this method returns None.
Returns:
username that was authenticated, or None.
           (type=string)

Since: fearow

is_authenticated(self)

Return true if this session is active and authenticated.
Returns:
True if the session is still open and has been authenticated successfully; False if authentication failed and/or the session is closed.
           (type=bool)

Generated by Epydoc 2.0 on Thu Jun 30 20:46:58 2005 http://epydoc.sf.net