Core Functionality
- class ssh2.core.SSHConnect(**configs: dict)[source]
Creates a new
ssh2.SSH`
into the decorated method.This class supports all keys from
ssh2.config.SSHConfigData
, however, thehostname
key must be provided.
- class ssh2.core.SSHContext(**configs: dict)[source]
Creates a new
ssh2.SSH`
as a context.This class supports all keys from
ssh2.config.SSHConfigData
, however, thehostname
key must be provided.- connect(configs: ssh2.config.SSHConfigData) None
Establishes SSH connection to server.
Connects to SSH server and authenticates following order of priority set by paramiko – see
paramiko.connect
.- Parameters
configs –
ssh2.config.SSHConfigData
object.- Returns
None.
- disconnect() NoReturn
Close SSH connection.
Terminates SSH connection and its underlying
paramiko.Transport
.
- execute(command: str, file: Union[None, TextIO] = None) Tuple[str, int]
Execute a command on the SSH server.
The command’s output stream is returned along with the exit status code.
- Parameters
command – command to execute.
file – an optional file-pointer object to write the output to.
- Returns
a 2-tuple with the STDOUT and exit status code of the executing command.
- execute_realtime(command: str) int
Execute a command on the SSH server.
The command’s output stream is immediately printed to the terminal.
- Parameters
command – command to execute.
- Returns
exit status code of the executing command
- open_sftp()
Open an SFTP session on the SSH server.
Note
This exposes the
paramiko.open_sftp
session object, please view the documentation at http://docs.paramiko.org/en/stable/api/sftp.html.- Returns
paramiko.SFTPClient
session object
- open_tunnel(configs: ssh2.config.SSHConfigData, dest_hostname: str, dest_port: Optional[int] = 22) paramiko.channel.Channel
Requests a new channel through an intermediary host.
Creates a socket-like object used for establish connects to unreachable hosts, similarily to how the
paramiko.ProxyCommand
works.- Parameters
dest_hostname – The destination hostname of this port forwarding.
dest_port – The destination port. Default 22.
configs –
ssh2.config.SSHConfigData
object.
- Returns
paramiko.Channel
object.- Raises
- class ssh2.core.SSHTunnelContext(tunnel_configs: ssh2.config.SSHConfigData, configs: ssh2.config.SSHConfigData)[source]
Creates a new
ssh2.SSH`
into the decorated method.This class supports all keys from
ssh2.config.SSHConfigData
, however, thehostname
key must be provided.Provides an interface to create a SSH connection through a tunnel to an “unreachable” host. It’s recommended that a tunnel should be completed using the SSH configuration file (ProxyCommand), however for instances where that is not possible, this context will provide this functionality.
- Parameters
tunnel_configs –
ssh2.SSHConfigData
object with the tunnel configurations.configs –
ssh2.SSHConfigData
object with the destination host configurations.
- connect(configs: ssh2.config.SSHConfigData) None
Establishes SSH connection to server.
Connects to SSH server and authenticates following order of priority set by paramiko – see
paramiko.connect
.- Parameters
configs –
ssh2.config.SSHConfigData
object.- Returns
None.
- disconnect() NoReturn
Close SSH connection.
Terminates SSH connection and its underlying
paramiko.Transport
.
- execute(command: str, file: Union[None, TextIO] = None) Tuple[str, int]
Execute a command on the SSH server.
The command’s output stream is returned along with the exit status code.
- Parameters
command – command to execute.
file – an optional file-pointer object to write the output to.
- Returns
a 2-tuple with the STDOUT and exit status code of the executing command.
- execute_realtime(command: str) int
Execute a command on the SSH server.
The command’s output stream is immediately printed to the terminal.
- Parameters
command – command to execute.
- Returns
exit status code of the executing command
- open_sftp()
Open an SFTP session on the SSH server.
Note
This exposes the
paramiko.open_sftp
session object, please view the documentation at http://docs.paramiko.org/en/stable/api/sftp.html.- Returns
paramiko.SFTPClient
session object
- open_tunnel(configs: ssh2.config.SSHConfigData, dest_hostname: str, dest_port: Optional[int] = 22) paramiko.channel.Channel
Requests a new channel through an intermediary host.
Creates a socket-like object used for establish connects to unreachable hosts, similarily to how the
paramiko.ProxyCommand
works.- Parameters
dest_hostname – The destination hostname of this port forwarding.
dest_port – The destination port. Default 22.
configs –
ssh2.config.SSHConfigData
object.
- Returns
paramiko.Channel
object.- Raises