ssh_paramiko package

Submodules

ssh_paramiko.ssh_paramiko module

class ssh_paramiko.ssh_paramiko.RemoteServer(key_ssh, **kwargs)

Bases: loggers.loggers.Loggers

Access remote server

Provide a layer of abstraction for accessing, executing commands and transfering files between a host and a server.

Parameters:
  • key_ssh (str) – path of the ssh private key to connect (must be None if using user and pasword to connect)
  • log_folder (str, optional , default =None) – folder where the log files of this class will be generated
  • username (str, optional , default =root) – username using the connection
  • password (str,optional, default =None) – password for connection if using user and password instead of key
  • ssh_port (str, optional, default =22) – ssh tcp port
  • server_has_dns (bool, optional, default =True) – if the server is not registered in a _d_n_s domain and/or has not its _d_n_s name equals to its hostname, this flag must be set to False, otherwise this condition will be checked to certify we are trully connected to the right server.
close_connection()

Closes remote server connection

Returns:True if successfully disconnected, False otherwise
Return type:bool
connect_server(server, ping=True)

Connects a host and a server via ssh

Parameters:
  • server (str) – remote server
  • ping (bool, default = True) – if False, ignores if the remote server does not ping back
Returns:

True if successfully connected, False otherwise

Return type:

ret (bool)

Returns:

Message of error if cannot connect, empty string otherwise

Return type:

msg (str)

execute_cmd(cmd, timeout=20)

_executes a command in a remote server shell

Parameters:
  • cmd (str) – command
  • timeout (str) – timeout to the command execution (default: 20)
Returns:

True if command successfully executed, False otherwise

Return type:

ret (bool)

Returns:

command standard output

Return type:

output (str)

Returns:

command standard error

Return type:

error (str)

get_file(local_file_path, remote_file_path, callback=None)

Transfers a remote file to a local file

Parameters:
  • local_file_path (str) – path of the local file
  • remote_file_path (str) – path of the remote file
  • callback (callback) – callback that reports file transfer status (bytes transfered and total bytes) _default: None
Returns:

True if successfully transfered, False otherwise

Return type:

bool

static ping_server(server, tries=4)

Connects a host and a server via ssh

Parameters:
  • server (str) – remote server
  • ping (bool, default = True) – if False, ignores if the remote server does not ping back
Returns:

True if successfully connected, False otherwise

Return type:

ret (bool)

Returns:

Message of error if cannot connect, empty string otherwise

Return type:

msg (str)

put_file(local_file_path, remote_file_path, callback=None)

Transfers a local file to a remote file

Parameters:
  • local_file_path (str) – path of the local file
  • remote_file_path (str) – path of the remote file
  • callback (callback) – callback that reports file transfer status (bytes transfered and total bytes) _default: None
Returns:

True if successfully transfered, False otherwise

Return type:

bool

static transfer_progress_bar(transfered_bytes, total_bytes)

Provides a transfer progress bar

Given a file to be transfered, print a progress bar according to the bytes transfered yet and the file size to be used as a callback for the methods put_file and get_file.

Parameters:
  • transfered_bytes (str, int or float) – bytes transfered
  • total_bytes (int or float) – size of file in bytes
validate_files(local_file_path, remote_file_path)

_checks if a remote and local files has the same sha1sum

Parameters:
  • local_file_path (str) – path of the local file to be validated
  • remote_file_path (str) – path of the remote file to be validated
Returns:

True if files’ sha1sums are the same, False otherwise

Return type:

bool

Module contents