Repository navigation
fix(ftp): fall back to PASV and keep data connections on the control host - #614
Conversation
…host FTP downloads from ftp.gnu.org and test.rebex.net failed with "Connection refused" on every data connection behind a NAT/proxy that drops EPSV data ports, while curl downloads them: curl falls back to PASV when the EPSV connection fails, and ignores the address a PASV reply names. RealFtpClient now does both. A data connection that cannot reach the EPSV port retries with PASV, and the connection skips EPSV from then on. PASV data connections go to the control host: servers behind NAT name a private address or 0.0.0.0, and a server should not send the client elsewhere.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e3c11d5f32
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Test Results 2 194 files + 1 2 222 suites +1 57m 58s ⏱️ + 1m 17s Results for commit 4adc24c. ± Comparison against base commit 94bd6b5. This pull request removes 1 and adds 11 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
Resolving the host again for a data connection can reach another server of a round-robin name, which is not listening on the passive port. Data connections now go to the numeric address the control connection reached, for EPSV and PASV alike.
Found while downloading from public FTP servers with the CLI:
ftp://ftp.gnu.org/...andftp://demo:[email protected]/readme.txtfailed withConnection refusedon every data connection, whilecurldownloads both from the same machine.Why
Here, the network path (a NAT/proxy) drops connections to EPSV data ports. curl copes in two ways that Ketch did not:
PASV. Ketch only fell back to PASV when the server refused the EPSV command.PASVreply names and connects to the control host (its default since 7.74). GNU's server answers227 Entering Passive Mode (0,0,0,0,…), and many servers behind NAT name a private address. Ketch dialed whatever address the reply named, so a server could also send it to another host.What changes
RealFtpClient.openPassiveDataConnection: if the EPSV port cannot be reached (refused or timed out), it sendsPASVinstead, and the connection skips EPSV for later transfers.ScriptedFtpServer(jvmTest) can answerPASV, name an unreachable EPSV port, and no longer needs a TLS context for plain sessions.Verification
ketchbuilt from this branch: GNUhello-2.12.tar.gz(SHA-256 matches the HTTPS copy), GNUgcc-14.2.0.tar.xz(88 MB, segmented, ~3 MB/s) and Rebexreadme.txt(matches curl) all complete. Before: all failed after retries.RealFtpClientPassiveTest: an unreachable EPSV port falls back to PASV (and later transfers skip EPSV); a PASV reply naming TEST-NET-1 still downloads from the control host. With the old host handling, the second test fails../gradlew :library:ftp:jvmTestpasses.