Provider package for Apache Airflow that enables FTP file transfer protocol operations including hooks, operators, and sensors for workflow integration.
npx @tessl/cli install tessl/pypi-apache-airflow-providers-ftp@3.13.0A comprehensive provider package for Apache Airflow that enables File Transfer Protocol (FTP) operations within data workflows. This provider includes hooks for managing FTP connections, operators for file transfer tasks, and sensors for monitoring file availability, making it essential for ETL pipelines and data integration workflows that require reliable file transfer capabilities.
pip install apache-airflow-providers-ftp# Hook imports for FTP connections
from airflow.providers.ftp.hooks.ftp import FTPHook, FTPSHook
# Operator imports for file transfers
from airflow.providers.ftp.operators.ftp import FTPFileTransmitOperator, FTPSFileTransmitOperator, FTPOperation
# Sensor imports for file monitoring
from airflow.providers.ftp.sensors.ftp import FTPSensor, FTPSSensorfrom airflow import DAG
from airflow.providers.ftp.hooks.ftp import FTPHook
from airflow.providers.ftp.operators.ftp import FTPFileTransmitOperator
from airflow.providers.ftp.sensors.ftp import FTPSensor
from datetime import datetime
# Using FTP Hook directly in a task
def transfer_files_with_hook():
hook = FTPHook(ftp_conn_id='my_ftp_connection')
# Download a file
hook.retrieve_file('/remote/path/file.txt', '/local/path/file.txt')
# Upload a file
hook.store_file('/remote/path/upload.txt', '/local/path/upload.txt')
# List directory contents
files = hook.list_directory('/remote/directory')
return files
# Using FTP Operator in a DAG
dag = DAG('ftp_example', start_date=datetime(2023, 1, 1))
# Wait for file to appear on FTP server
wait_for_file = FTPSensor(
task_id='wait_for_data_file',
path='/remote/data/input.csv',
ftp_conn_id='my_ftp_connection',
dag=dag
)
# Download the file when available
download_file = FTPFileTransmitOperator(
task_id='download_data_file',
ftp_conn_id='my_ftp_connection',
operation=FTPOperation.GET,
remote_filepath='/remote/data/input.csv',
local_filepath='/local/data/input.csv',
dag=dag
)
wait_for_file >> download_fileThe FTP provider follows Apache Airflow's standard provider architecture:
All components support both standard FTP and secure FTPS (FTP over SSL/TLS) protocols.
Low-level hook classes for establishing and managing FTP connections with authentication, SSL support, and comprehensive file operations.
class FTPHook(BaseHook):
def __init__(self, ftp_conn_id: str = "ftp_default") -> None: ...
def get_conn(self) -> ftplib.FTP: ...
def close_conn(self) -> None: ...
def test_connection(self) -> tuple[bool, str]: ...
class FTPSHook(FTPHook):
def get_conn(self) -> ftplib.FTP: ...Operator classes for performing file uploads, downloads, and transfers between local and remote FTP servers with support for directory creation and batch operations.
class FTPFileTransmitOperator(BaseOperator):
def __init__(
self,
*,
ftp_conn_id: str = "ftp_default",
local_filepath: str | list[str],
remote_filepath: str | list[str],
operation: str = FTPOperation.PUT,
create_intermediate_dirs: bool = False,
**kwargs
) -> None: ...
class FTPSFileTransmitOperator(FTPFileTransmitOperator): ...
class FTPOperation:
PUT = "put"
GET = "get"Sensor classes for waiting and monitoring file or directory availability on FTP servers with configurable error handling and retry logic.
class FTPSensor(BaseSensorOperator):
def __init__(
self,
*,
path: str,
ftp_conn_id: str = "ftp_default",
fail_on_transient_errors: bool = True,
**kwargs
) -> None: ...
class FTPSSensor(FTPSensor): ...The FTP provider uses Airflow's connection system. Configure FTP connections in the Airflow UI or programmatically:
ftp"passive": true/false - Enable/disable passive mode (default: true)# Connection context manager support
FTPHook.__enter__() -> FTPHook
FTPHook.__exit__(exc_type: Any, exc_val: Any, exc_tb: Any) -> None
# Error handling types
tuple[bool, str] # test_connection return type