flexget.components.ftp.sftp_client module#
- class flexget.components.ftp.sftp_client.HandlerBuilder(sftp, url_prefix, private_key, private_key_pass, host_key)[source]#
Bases:
objectClass for building pysftp.Connection.walktree node handlers.
- Parameters:
- get_dir_handler(get_size, files_only, entry_accumulator)[source]#
Build a file node handler suitable for use with pysftp.Connection.walktree.
- get_file_handler(get_size, dirs_only, entry_accumulator)[source]#
Build a file node handler suitable for use with pysftp.Connection.walktree.
- class flexget.components.ftp.sftp_client.Handlers[source]#
Bases:
object- classmethod handle_directory(sftp, prefix, get_size, files_only, private_key, private_key_pass, host_key, entry_accumulator, path)[source]#
Directory node handler. Adds a directory entry to entry_accumulator.
- Parameters:
sftp (pysftp.Connection) – A pysftp.Connection object
logger – a logger object
prefix (str) – SFTP URL prefix
get_size (bool) – boolean indicating whether to compute the size of each directory
files_only (bool) – Boolean indicating whether to skip directories
entry_accumulator (list[Entry]) – a list in which to store entries
private_key (str | None) – private key path
private_key_pass (str | None) – private key password
host_key (HostKey | None) – Host key for the remote server if not in known_hosts
path (str) – path to handle
- Return type:
None
- classmethod handle_file(sftp, prefix, get_size, dirs_only, private_key, private_key_pass, host_key, entry_accumulator, path)[source]#
File node handler. Adds a file entry to entry_accumulator.
- Parameters:
sftp (pysftp.Connection) – A pysftp.Connection object
logger – a logger object
prefix (str) – SFTP URL prefix
get_size (bool) – boolean indicating whether to compute the size of each file
dirs_only (bool) – boolean indicating whether to skip files
private_key (str | None) – private key path
private_key_pass (str | None) – private key password
host_key (HostKey | None) – Host key for the remote server if not in known_hosts
entry_accumulator (list[Entry]) – a list in which to store entries
path (str) – path to handle
- Return type:
None
- static _get_entry(sftp, prefix, size_handler, get_size, path, private_key, private_key_pass, host_key)[source]#
- class flexget.components.ftp.sftp_client.HostKey(key_type, public_key)[source]#
Bases:
objectHost key used to connect to a SFTP server if not defined in known_hosts.
- class flexget.components.ftp.sftp_client.SftpClient(host, port, username, password=None, private_key=None, private_key_pass=None, host_key=None, connection_tries=3)[source]#
Bases:
object- Parameters:
- _connect(connection_tries)[source]#
- Parameters:
connection_tries (int)
- Return type:
pysftp.Connection
- download(source, to, recursive, delete_origin)[source]#
Download the file specified in “source” to the destination specified in “to”.
- Parameters:
source (str) – path of the resource to download
to (str) – path of the directory to download to
recursive (bool) – indicates whether to download the contents of “source” recursively
delete_origin (bool) – indicates whether to delete the source resource upon download, is the source is a symlink, only the symlink will be removed rather than it’s target.
- Return type:
None
- list_directories(directories, recursive, get_size, files_only, dirs_only)[source]#
Build a list of entries from a provided list of directories on an SFTP server.
- Parameters:
directories (list[str]) – list of directories to generate entries for
recursive (bool) – boolean indicating whether to list recursively
get_size (bool) – boolean indicating whether to compute size for each node (potentially slow for directories)
files_only (bool) – boolean indicating whether to exclude directories
dirs_only (bool) – boolean indicating whether to exclude files
- Returns:
a list of entries describing the contents of the provided directories
- Return type:
- make_dirs(path)[source]#
Build directories.
- Parameters:
path (str) – path to build
- Return type:
None
- remove_dir(path)[source]#
Remove a directory if it’s empty.
- Parameters:
path (str) – directory to remove
- Return type:
None
- remove_file(path)[source]#
Remove a file if it’s empty.
- Parameters:
path (str) – file to remove
- Return type:
None
- set_socket_timeout(socket_timeout_sec)[source]#
Set the SFTP client socket timeout.
- Parameters:
socket_timeout_sec – Socket timeout in seconds
- _handler_builder: HandlerBuilder#
- _sftp: pysftp.Connection#