SSH
- class ssh2.SSH[source]
A high-level representation of a session with an SSH server.
This class wraps the
paramiko.SSHClient
object to simplify most aspects of interacting with an SSH server.- connect(configs: ssh2.config.SSHConfigData) None [source]
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 [source]
Close SSH connection.
Terminates SSH connection and its underlying
paramiko.Transport
.
- execute(command: str, file: Union[None, TextIO] = None) Tuple[str, int] [source]
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 [source]
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()[source]
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 [source]
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