sshParamiko package

Submodules

sshParamiko.sshParamiko module

class sshParamiko.sshParamiko.RemoteServer(keySSH, **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:
  • keySSH (str) – path of the ssh private key to connect (must be None if using user and pasword to connect)
  • logFolder (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
  • sshPort (str, optional, default =22) – ssh tcp port
  • serverHasDns (bool, optional, default =True) – if the server is not registered in a DNS domain and/or has not its DNS name equals to its hostname, this flag must de set to False, otherwise this condition will be checked to certify we are trukky connected to the right server.
closeConnection()

Description: closes remote server connection

Returns:True if successfully disconnected, False otherwise
Return type:bool
connectServer(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)

executeCmd(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)

getFile(localFilePath, remoteFilePath, callBack=None)

Transfers a remote file to a local file

Parameters:
  • localFilePath (str) – path of the local file
  • remoteFilePath (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 pingServer(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)

putFile(localFilePath, remoteFilePath, callBack=None)

Transfers a local file to a remote file

Parameters:
  • localFilePath (str) – path of the local file
  • remoteFilePath (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 transferProgressBar(transferedBytes, totalBytes)

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 putFile and getFile.

Parameters:
  • transferedBytes (str, int or float) – bytes transfered
  • totalBytes (int or float) – size of file in bytes
validateFiles(localFilePath, remoteFilePath)

Checks if a remote and local files has the same sha1sum

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

True if files’ sha1sums are the same, False otherwise

Return type:

bool

Module contents