| :py:mod:`airflow.providers.sftp.hooks.sftp` |
| =========================================== |
| |
| .. py:module:: airflow.providers.sftp.hooks.sftp |
| |
| .. autoapi-nested-parse:: |
| |
| This module contains SFTP hook. |
| |
| |
| |
| Module Contents |
| --------------- |
| |
| Classes |
| ~~~~~~~ |
| |
| .. autoapisummary:: |
| |
| airflow.providers.sftp.hooks.sftp.SFTPHook |
| |
| |
| |
| |
| .. py:class:: SFTPHook(ssh_conn_id = 'sftp_default', *args, **kwargs) |
| |
| Bases: :py:obj:`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. |
| |
| :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. |
| |
| For consistency reasons with SSHHook, the preferred parameter is "ssh_conn_id". |
| Please note that it is still possible to use the parameter "ftp_conn_id" |
| to initialize the hook, but it will be removed in future Airflow versions. |
| |
| :param ssh_conn_id: The :ref:`sftp connection id<howto/connection:sftp>` |
| :param ftp_conn_id (Outdated): The :ref:`sftp connection id<howto/connection:sftp>` |
| |
| .. py:attribute:: conn_name_attr |
| :annotation: = ssh_conn_id |
| |
| |
| |
| .. py:attribute:: default_conn_name |
| :annotation: = sftp_default |
| |
| |
| |
| .. py:attribute:: conn_type |
| :annotation: = sftp |
| |
| |
| |
| .. py:attribute:: hook_name |
| :annotation: = SFTP |
| |
| |
| |
| .. py:method:: get_ui_field_behaviour() |
| :staticmethod: |
| |
| Returns custom field behaviour |
| |
| |
| .. py:method:: get_conn(self) |
| |
| Returns an SFTP connection object |
| |
| |
| .. py:method:: close_conn(self) |
| |
| Closes the connection |
| |
| |
| .. py:method:: describe_directory(self, path) |
| |
| Returns a dictionary of {filename: {attributes}} for all files |
| on the remote system (where the MLSD command is supported). |
| |
| :param path: full path to the remote directory |
| |
| |
| .. py:method:: list_directory(self, path) |
| |
| Returns a list of files on the remote system. |
| |
| :param path: full path to the remote directory to list |
| |
| |
| .. py:method:: create_directory(self, path, mode = 777) |
| |
| Creates a directory on the remote system. |
| |
| :param path: full path to the remote directory to create |
| :param mode: int representation of octal mode for directory |
| |
| |
| .. py:method:: delete_directory(self, path) |
| |
| Deletes a directory on the remote system. |
| |
| :param path: full path to the remote directory to delete |
| |
| |
| .. py:method:: retrieve_file(self, remote_full_path, local_full_path) |
| |
| Transfers the remote file to a local location. |
| If local_full_path is a string path, the file will be put |
| at that location |
| |
| :param remote_full_path: full path to the remote file |
| :param local_full_path: full path to the local file |
| |
| |
| .. py:method:: store_file(self, remote_full_path, local_full_path) |
| |
| 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 |
| |
| :param remote_full_path: full path to the remote file |
| :param local_full_path: full path to the local file |
| |
| |
| .. py:method:: delete_file(self, path) |
| |
| Removes a file on the FTP Server |
| |
| :param path: full path to the remote file |
| |
| |
| .. py:method:: get_mod_time(self, path) |
| |
| Returns modification time. |
| |
| :param path: full path to the remote file |
| |
| |
| .. py:method:: path_exists(self, path) |
| |
| Returns True if a remote entity exists |
| |
| :param path: full path to the remote file or directory |
| |
| |
| .. py:method:: get_tree_map(self, path, prefix = None, delimiter = None) |
| |
| 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. |
| |
| :param path: path from which tree will be built |
| :param prefix: if set paths will be added if start with prefix |
| :param delimiter: if set paths will be added if end with delimiter |
| :return: tuple with list of files, dirs and unknown items |
| :rtype: Tuple[List[str], List[str], List[str]] |
| |
| |
| .. py:method:: test_connection(self) |
| |
| Test the SFTP connection by calling path with directory |
| |
| |
| .. py:method:: get_file_by_pattern(self, path, fnmatch_pattern) |
| |
| Returning the first matching file based on the given fnmatch type pattern |
| |
| :param path: path to be checked |
| :param fnmatch_pattern: The pattern that will be matched with `fnmatch` |
| :return: string containing the first found file, or an empty string if none matched |
| |
| |
| |