airflow.providers.sftp.hooks.sftp

This module contains SFTP hook.

Module Contents

class airflow.providers.sftp.hooks.sftp.SFTPHook(ftp_conn_id: str = 'sftp_default', *args, **kwargs)[source]

Bases: airflow.providers.ssh.hooks.ssh.SSHHook

This hook is inherited from SSH hook. Please refer to SSH hook for the input arguments.

Interact with SFTP. Aims to be interchangeable with FTPHook.

Pitfalls:
  • In contrast with FTPHook describe_directory only returns size, type and modify. It doesn't return unix.owner, unix.mode, perm, unix.group and unique.

  • retrieve_file and store_file only take a local full path and not a

    buffer.

  • If no mode is passed to create_directory it will be created with 777 permissions.

Errors that may occur throughout but should be handled downstream.

Parameters

sftp_conn_id (str) -- The sftp connection id

conn_name_attr = ftp_conn_id[source]
default_conn_name = sftp_default[source]
conn_type = sftp[source]
hook_name = SFTP[source]
static get_ui_field_behaviour()[source]
get_conn(self)[source]

Returns an SFTP connection object

close_conn(self)[source]

Closes the connection

describe_directory(self, path: str)[source]

Returns a dictionary of {filename: {attributes}} for all files on the remote system (where the MLSD command is supported).

Parameters

path (str) -- full path to the remote directory

list_directory(self, path: str)[source]

Returns a list of files on the remote system.

Parameters

path (str) -- full path to the remote directory to list

create_directory(self, path: str, mode: int = 777)[source]

Creates a directory on the remote system.

Parameters
  • path (str) -- full path to the remote directory to create

  • mode -- int representation of octal mode for directory

delete_directory(self, path: str)[source]

Deletes a directory on the remote system.

Parameters

path (str) -- full path to the remote directory to delete

retrieve_file(self, remote_full_path: str, local_full_path: str)[source]

Transfers the remote file to a local location. If local_full_path is a string path, the file will be put at that location

Parameters
  • remote_full_path (str) -- full path to the remote file

  • local_full_path (str) -- full path to the local file

store_file(self, remote_full_path: str, local_full_path: str)[source]

Transfers a local file to the remote location. If local_full_path_or_buffer is a string path, the file will be read from that location

Parameters
  • remote_full_path (str) -- full path to the remote file

  • local_full_path (str) -- full path to the local file

delete_file(self, path: str)[source]

Removes a file on the FTP Server

Parameters

path (str) -- full path to the remote file

get_mod_time(self, path: str)[source]

Returns modification time.

Parameters

path (str) -- full path to the remote file

path_exists(self, path: str)[source]

Returns True if a remote entity exists

Parameters

path (str) -- full path to the remote file or directory

static _is_path_match(path: str, prefix: Optional[str] = None, delimiter: Optional[str] = None)[source]

Return True if given path starts with prefix (if set) and ends with delimiter (if set).

Parameters
  • path (str) -- path to be checked

  • prefix (str) -- if set path will be checked is starting with prefix

  • delimiter (str) -- if set path will be checked is ending with suffix

Returns

bool

get_tree_map(self, path: str, prefix: Optional[str] = None, delimiter: Optional[str] = None)[source]

Return tuple with recursive lists of files, directories and unknown paths from given path. It is possible to filter results by giving prefix and/or delimiter parameters.

Parameters
  • path (str) -- path from which tree will be built

  • prefix (str) -- if set paths will be added if start with prefix

  • delimiter (str) -- if set paths will be added if end with delimiter

Returns

tuple with list of files, dirs and unknown items

Return type

Tuple[List[str], List[str], List[str]]

Was this entry helpful?