blob: 2af2db925e067aeed1db57e813320a991a01c82f [file] [log] [blame]
:py:mod:`airflow.providers.sftp.operators.sftp`
===============================================
.. py:module:: airflow.providers.sftp.operators.sftp
.. autoapi-nested-parse::
This module contains SFTP operator.
Module Contents
---------------
Classes
~~~~~~~
.. autoapisummary::
airflow.providers.sftp.operators.sftp.SFTPOperation
airflow.providers.sftp.operators.sftp.SFTPOperator
.. py:class:: SFTPOperation
Operation that can be used with SFTP
.. py:attribute:: PUT
:annotation: = put
.. py:attribute:: GET
:annotation: = get
.. py:class:: SFTPOperator(*, ssh_hook = None, sftp_hook = None, ssh_conn_id = None, remote_host = None, local_filepath, remote_filepath, operation = SFTPOperation.PUT, confirm = True, create_intermediate_dirs = False, **kwargs)
Bases: :py:obj:`airflow.models.BaseOperator`
SFTPOperator for transferring files from remote host to local or vice a versa.
This operator uses sftp_hook to open sftp transport channel that serve as basis
for file transfer.
:param ssh_conn_id: :ref:`ssh connection id<howto/connection:ssh>`
from airflow Connections. `ssh_conn_id` will be ignored if `ssh_hook`
or `sftp_hook` is provided.
:param sftp_hook: predefined SFTPHook to use
Either `sftp_hook` or `ssh_conn_id` needs to be provided.
:param ssh_hook: Deprecated - predefined SSHHook to use for remote execution
Use `sftp_hook` instead.
:param remote_host: remote host to connect (templated)
Nullable. If provided, it will replace the `remote_host` which was
defined in `sftp_hook`/`ssh_hook` or predefined in the connection of `ssh_conn_id`.
:param local_filepath: local file path to get or put. (templated)
:param remote_filepath: remote file path to get or put. (templated)
:param operation: specify operation 'get' or 'put', defaults to put
:param confirm: specify if the SFTP operation should be confirmed, defaults to True
:param create_intermediate_dirs: create missing intermediate directories when
copying from remote to local and vice-versa. Default is False.
Example: The following task would copy ``file.txt`` to the remote host
at ``/tmp/tmp1/tmp2/`` while creating ``tmp``,``tmp1`` and ``tmp2`` if they
don't exist. If the parameter is not passed it would error as the directory
does not exist. ::
put_file = SFTPOperator(
task_id="test_sftp",
ssh_conn_id="ssh_default",
local_filepath="/tmp/file.txt",
remote_filepath="/tmp/tmp1/tmp2/file.txt",
operation="put",
create_intermediate_dirs=True,
dag=dag
)
.. py:attribute:: template_fields
:annotation: :Sequence[str] = ['local_filepath', 'remote_filepath', 'remote_host']
.. py:method:: execute(context)
This is the main method to derive when creating an operator.
Context is the same dictionary used as when rendering jinja templates.
Refer to get_template_context for more context.