Skip to content

Sshclient

flowtask.interfaces.SSHClient

SSHClient

SSHClient(*args, tunnel=None, **kwargs)

Bases: ClientInterface

SSHClient

Overview

The SSHClient class is a component for managing SSH and SFTP connections. It provides methods for establishing connections,
running commands, downloading, uploading, and copying files using SFTP. It supports various SSH algorithms and handles
errors gracefully.

.. table:: Properties :widths: auto

+------------------+----------+-----------+--------------------------------------------------------------------------------------+
| Name             | Required | Description                                                                                      |
+------------------+----------+-----------+--------------------------------------------------------------------------------------+
| block_size       |   No     | The block size for file transfers, defaults to 16384 bytes.                                      |
+------------------+----------+-----------+--------------------------------------------------------------------------------------+
| max_requests     |   No     | The maximum number of concurrent requests, defaults to 128.                                      |
+------------------+----------+-----------+--------------------------------------------------------------------------------------+
| algorithms       |   No     | A list of supported SSH algorithms.                                                              |
+------------------+----------+-----------+--------------------------------------------------------------------------------------+
| commands         |   No     | A list of commands to run over SSH.                                                              |
+------------------+----------+-----------+--------------------------------------------------------------------------------------+
| only_sftp        |   No     | A flag indicating if only SFTP connections are allowed.                                          |
+------------------+----------+-----------+--------------------------------------------------------------------------------------+
| tunnel           |   Yes    | Describes an SSH tunnel connection                                                               |
+------------------+----------+-----------+--------------------------------------------------------------------------------------+
| _connection      |   Yes    | The current SSH connection object.                                                               |
+------------------+----------+-----------+--------------------------------------------------------------------------------------+
| _clientargs      |   Yes    | Arguments for the SSH client configuration.                                                      |
+------------------+----------+-----------+--------------------------------------------------------------------------------------+
| client_keys      |   Yes    | SSH public key                                                                                   |
+------------------+----------+--------------------------------------------------------------------------------------------------+
| source           |   Yes    | List of algorithms to be used in connection encryption                                           |
+------------------+----------+--------------------------------------------------------------------------------------------------+

Return

The methods in this class facilitate SSH and SFTP operations, including establishing connections, 
file transfers, command execution, and handling SSH tunnels. The class also manages environment settings 
and provides error handling mechanisms specific to SSH and SFTP operations.

close async

close(timeout=1, reason='Connection Ended.')

Close Method.

copy_files async

copy_files(file, destination, preserve=False, recurse=False)

copy_files.

Use can copy/move one or more files (or directories) in server. Args: file (Union[str,List[PurePath]]): Path (purepath) or list of paths for files or directories destination (Purepath or str): remote destination of upload preserve (bool, optional): preserve the original attributes. Defaults False. recurse (bool, optional): copy recursively all directories. Defaults False. Returns: bool: file(s) or directorires were uploaded or not.

download_files async

download_files(file, destination, preserve=False, recurse=False)

download_file

Download a File from sFTP based on Path. Args: path (str): file to be downloaded TODO: Support for write_into and Renaming Files.

open async

open(host, port, credentials, **kwargs)

init an SSH connection

sftp_client async

sftp_client()

sftp_client. Starts a SFTP client connection.

upload_files async

upload_files(file, destination, preserve=False, recurse=False)

upload_files.

Use can upload one or more files (or directories) recursively. Args: file (Union[str,List[PurePath]]): Path (purepath) or list of paths for files or directories destination (Purepath or str): remote destination of upload preserve (bool, optional): preserve the original attributes. Defaults False. recurse (bool, optional): copy recursively all directories. Defaults False. Returns: bool: file(s) or directorires were uploaded or not.