Skip to content

Add FTP support for ObjectStoragePath - #77716

Open
yuseok89 wants to merge 7 commits into
apache:mainfrom
yuseok89:aip-132-ftp-filesystem
Open

yuseok89 wants to merge 7 commits into
apache:mainfrom
yuseok89:aip-132-ftp-filesystem

Conversation

@yuseok89

@yuseok89 yuseok89 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

This lets ObjectStoragePath work with FTP paths such as ftp://my_conn@/data/file.csv, using the FTP implementation that ships with fsspec. It is the first step for the FTP operators in phase 1 of AIP-132.

It reads the host, port, login and password from the FTP connection, along with the passive and encoding extras. fsspec has no option for active mode, so a small subclass applies passive on every connect. The same subclass checks the control connection before each command it sends and reconnects when the server has closed it. FTPS is left out, since fsspec does not re-apply prot_p() after a reconnect and does not verify the server certificate the way FTPSHook does.

Testing

  • Unit tests for the connection mapping, passive mode and reconnection.
  • Reads, writes, listing, copies, moves and deletes worked against a vsftpd server in a local Docker container, in both passive and active mode, and listing and reading recovered after the server closed an idle connection.

cc @dabla


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)
    • Claude Code (Opus 5.5)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@github-actions github-actions Bot added the fork ci required Gated by AIP-120: CI must pass in the contributor's fork. Managed by the fork CI reconciler. label Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fork CI: failed. CI for the latest commit failed in your fork. Fix the failures and push again.

Pull requests from contributors run their CI in the contributor's own fork. GitHub Actions is free and has no minute limit on public forks, while the CI capacity of the Apache Software Foundation is shared by every ASF project and is finite.

Latest run: https://github.com/yuseok89/airflow/actions/runs/46686780383

Jobs that did not pass:

How this works: CI in your fork.


This comment was posted automatically by the fork CI monitor from templates drafted with an AI-assisted tool, so it may contain mistakes. An Apache Airflow maintainer, a real person, will review the pull request once its fork CI is green. Why the first pass is automated.

@dabla dabla left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yuseok89 for the effort already, really nice to see this involvement on such short notice.

Addressed

Nothing since the previous round: this is the first review, and the PR has no other review threads.

Open

  • [1] the host part of the URL is ignored, the docs say otherwise (warning).
  • [4] a dead control connection makes ls return an empty list; the store cache keeps the connection for the life of the process (warning).
  • [2] same-connection copy raises NotImplementedError; worth a line in the docs (nit).
  • [3] fsspec imported but not declared as a dependency (nit).
  • CI: fork CI is green (28 jobs, merged with main@577554cd1d); the only pending check is WIP, because the PR is a draft.

Two notes for AIP-132 phase 1 that need no change in this PR:

  • Remote to remote goes through open(), and on FTP that is one data connection per block. _cp_file is shutil.copyfileobj between two opened files. Against the local server, reading 8 MiB that way took 32 RETR (each with REST) and 31 ABOR, where fs.get_file took one RETR; writing 1 MiB took 5 STOR with REST. That is roughly 4,000 data connections and aborts per GiB for FTPToS3, and the write side needs a server that accepts REST before STOR. Local to FTP and FTP to local are not affected (put/get). Something for the grown FileTransferOperator to handle (a larger block_size, or a spooled get_file/put_file for FTP ends) and for the shared behaviour suite to cover. Timings on localhost say nothing about a real server, so I give only the command counts.
  • FTPS. Leaving it out is right for this PR. For the record: fsspec has had tls= since 2024.9.0, calls prot_p() once in __init__ but not after a reconnect, and builds FTP_TLS without the verified context FTPSHook passes. None of the 28 phase 1 operators uses FTPSHook (FTPToS3Operator and S3ToFTPOperator use FTPHook).

The pass: head b4965c0ceb, diff-based, with the unchanged callers read at that commit (task-sdk/src/airflow/sdk/io/{fs,store,path}.py, FTPHook, the sftp fs module) and fsspec's implementations/ftp.py. The change matches the AIP's phase 1 row for ftp (an fs module plus the provider.yaml entry, as sftp did). Parity with FTPHook.get_conn checked field by field: host, port default, anonymous login, passive (same helper, applied on every _connect), encoding; the only difference is fsspec's 30 s socket timeout, which the hook does not set. All mocks in the tests carry a spec; nothing names a reviewer. Probes run: path resolution through ObjectStoragePath with a mocked ftplib.FTP, and reads, writes, copy, active mode (the server saw PORT, no PASV) and the idle timeout against pyftpdlib. The PR's unit tests were not run locally; fork CI ran them.

Comment thread providers/ftp/docs/filesystems/ftp.rst Resolved
Comment thread providers/ftp/docs/filesystems/ftp.rst Resolved
@yuseok89
yuseok89 force-pushed the aip-132-ftp-filesystem branch from bdab678 to f1aa05e Compare November 29, 2026 01:32
@yuseok89
yuseok89 marked this pull request as ready for review November 29, 2026 03:24
@github-actions github-actions Bot added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Nov 29, 2026

@dabla dabla left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

  • URL host ignored, docs said otherwise (thread): fixed in 78c3c52046. The page now says host and port come from the connection and the example is ftp://my_conn@/data/file.csv.
  • Same-connection copy not documented (thread): fixed in 78c3c52046, with the note that a move works.
  • fsspec not declared (thread): fsspec>=2023.10.0 is in providers/ftp/pyproject.toml, with the regenerated README, docs index and uv.lock.
  • Dead control connection read as an empty folder (thread): fixed in 78c3c52046 and f1aa05e727. I re-ran the first round's scenario against the head's _AirflowFTPFileSystem (pyftpdlib, 2 s idle timeout): after the idle period ls("/sub") lists the file, a read returns the bytes and exists() is right; with the server stopped the call raises ConnectionRefusedError, and once the server is back the next call reconnects and reads. Every method of fsspec's FTP filesystem that sends a command goes through _ensure_connected; the one path left out (reads and writes on an already open file) is named in the docstring.

Open

  • [2] directory listings are cached without expiry in a filesystem that lives as long as the process, so files created by others are not seen (warning).
  • [1] passive as a string is not normalised without a connection id (nit).
  • CI: green, 12 passed, nothing pending; the PR is no longer a draft.

The pass: head f1aa05e727, diff-based, whole change re-read (not only the two fix commits), with fsspec's implementations/ftp.py and spec.py for the listing cache. The four first-round threads were each re-run or re-read against the head as listed above. Override signatures checked against the parent's callers (AbstractFileSystem.open passes block_size, autocommit and cache_options by keyword, so the narrower _open signature is safe). All mocks in the tests carry a spec; nothing in the change, the commit messages or the PR body names a reviewer. The PR's unit tests were not run locally; fork CI ran them.

@github-actions github-actions Bot removed the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Nov 30, 2026
@yuseok89
yuseok89 force-pushed the aip-132-ftp-filesystem branch from b870543 to c50aa86 Compare November 30, 2026 12:37
@github-actions github-actions Bot added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Nov 30, 2026

@dabla dabla left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

  • Stale directory listings (thread): fixed in c50aa868fa. Listings now expire after 10 seconds by default. Re-run against the head's filesystem on a local pyftpdlib server: a file created by another client was seen by exists() after 10.0 s, and after the server's idle timeout plus the expiry ls reconnected and listed both files. use_listings_cache=False and a custom listings_expiry_time are still accepted. The docs state the default, the truncated read of a file rewritten inside the window (I got b'abc' for a file rewritten to ten bytes, and the full content after invalidate_cache()), and the way out.
  • passive as a string without a connection id (thread): fixed in c50aa868fa, parsed once in __init__. With no connection id, "false" and False now give active mode (the server saw PORT), "true" and True passive (PASV).

Open

  • [1] the name of the filesystem class (nit).
  • CI: all tests are green on this head, fork CI tests included (11 checks passed); only the "Mergeable" policy check is pending.

The pass: head c50aa868fa, diff-based, the whole change re-read and both second-round scenarios re-run as listed above. The idle-plus-expiry run shows that the ls override treats an expired listing as a miss and checks the connection first. All mocks in the tests carry a spec; nothing in the change, the commit messages or the PR body names a reviewer. The PR's unit tests were not run locally; fork CI ran them.

@github-actions github-actions Bot added ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. and removed ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. labels Nov 30, 2026
@github-actions github-actions Bot removed the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers fork ci required Gated by AIP-120: CI must pass in the contributor's fork. Managed by the fork CI reconciler. kind:documentation provider:ftp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants