katnip.utils.sshutils module

class katnip.utils.sshutils.ReconnectingSSHConnection(hostname, port, username, password, use_scp=False, scp_sanitize=None)

Bases: object

A wrapper around paramiko’s SSHClient which handles connection dropouts gracefully.

__init__(hostname, port, username, password, use_scp=False, scp_sanitize=None)
Parameters:
  • hostname – ssh server hostname or ip
  • port – ssh server port
  • username – ssh login username
  • password – ssh login password
  • use_scp – use the SCP protocol for transferring files instead of SFTP (default: False)
  • scp_sanitize – sanitization function used on filenames passed to the scp module, if used. (defaut: no sanitization)
close()

Close the connection

exec_command(command)

Execute a command on the ssh server.

Parameters:command – the command string to execute
Returns:a tuple of the return_code from the command, the stdout output and the stderr output
get(remotepath, localpath)

Get a file from the ssh server using sftp or scp.

Parameters:
  • remotepath – the remote path of the file to be copied
  • localpath – the local path to which the file should be copied
Raises:

OSException or IOException if file not found

put(localpath, remotepath)

Put a file on the ssh server using sftp or scp.

Parameters:
  • localpath – the local path to the file to copy
  • remotepath – the remote path to which the file should be copied
Raises:

OSException or IOException if file not found

remove(remotepath)

Remove a file from the ssh server using sftp or scp.

Parameters:remotepath – the remote path of the file to be removed
Raises:OSException or IOException if file not found