util.sftp¶
Wrapper around Paramiko SFTP functionality and related exceptions.
Exceptions¶
Custom exception for any SFTP-related failures. |
Classes¶
Wrapper around Paramiko SFTP functionality. |
Module Contents¶
- exception util.sftp.SftpError[source]¶
Bases:
ExceptionCustom exception for any SFTP-related failures.
- class util.sftp.SftpClient(overrides=None)[source]¶
Wrapper around Paramiko SFTP functionality.
If instantiated without overrides, reads settings from BackupOptions(pk=1). Optionally, an overrides dict can supply:
host, port, user, auth_method, password, private_key, key_passphrase, local_storage, remote_directory.
- Parameters:
overrides (dict[str, Any] | None)
- _load_private_key()[source]¶
Load a Paramiko PKey from the stored private_key_text and passphrase.
- Returns:
A Paramiko PKey object.
- Raises:
SftpError – If key loading fails or no key provided.
- Return type:
paramiko.PKey
- _connect_sftp()[source]¶
Establish an SFTP connection and return the Transport and SFTPClient.
- Returns:
A tuple of (Transport, SFTPClient).
- Raises:
SftpError – If no auth_method is set or authentication/SSH errors occur.
- Return type:
tuple[paramiko.Transport, paramiko.SFTPClient]
- test_connection()[source]¶
Attempt an SFTP connection with the current settings.
- Raises:
SftpError – If no auth_method, authentication fails, or any SSH error.
- Return type:
None
- upload_file(local_filepath, remote_path)[source]¶
Upload a single local file to the remote_path via SFTP.
- Parameters:
local_filepath (pathlib.Path) – Path to the local file to upload.
remote_path (str) – Full remote path (including filename) at the server.
- Raises:
SftpError – If no auth_method, local file missing, or any SSH/SFTP error.
- Return type:
None