Skip to content

fix(ftp): speak implicit FTPS on port 990 and fail fast on TLS reuse - #615

Merged
linroid merged 1 commit into
mainfrom
fix/ftps-implicit-tls
Oct 23, 2026
Merged

linroid merged 1 commit into
mainfrom
fix/ftps-implicit-tls

Conversation

@linroid

@linroid linroid commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Follows #614 (merged), which touched the same files.

Found while downloading from Rebex's public FTPS test server (test.rebex.net) with the CLI.

1. ftps:// on its default port hung forever

FtpUrl defaults ftps:// to port 990, which is implicit FTPS: the server expects a TLS handshake as soon as the connection opens. RealFtpClient only spoke explicit FTPS: it waited for a plaintext 220 greeting and then sent AUTH TLS. Neither side ever spoke, and ketch ftps://demo:[email protected]/readme.txt hung until it was killed.

Now an ftps:// URL on port 990 (FtpUrl.implicitTls) opens its control connection with TLS before reading the greeting, and upgradeToTls() only sends PBSZ 0 / PROT P. This is how curl and FileZilla read ftps://. Other ports (e.g. ftps://host:21/) keep explicit AUTH TLS, so existing setups behave as before.

2. Servers requiring TLS session reuse were retried for minutes

ktor-network-tls cannot resume TLS sessions (a known, documented limit). Servers that require data connections to resume the control session therefore refuse every transfer: Rebex, vsftpd with its default require_ssl_reuse=YES, and FileZilla Server. They say why in the transfer's final reply (425 Cannot secure data connection - TLS session resumption required.), but Ketch only logged that as a warning and retried a generic short transfer. Before: 114 s of retries ending in FTP connection closed prematurely: received 0 of 95 bytes.

Now retrieve() throws the error reply a transfer ends with, and FtpError.fromReply reads the session-reuse refusals of Rebex, vsftpd and FileZilla Server as KetchError.Unsupported, which is not retried. The download fails in about 10 s with:

Download failed: Not supported: The FTPS server requires data connections to resume the control connection's TLS session, which Ketch cannot do (FTP 425: Cannot secure data connection - TLS session resumption required.)

Verification

  • ketch from this branch against test.rebex.net: implicit (:990) now connects, logs in and reads SIZE/MDTM over TLS. Both implicit and explicit (:21) transfers fail in ~10 s with the message above, as Rebex requires session resumption.
  • New tests: RealFtpClientTlsTest.retrieve_implicitTls_securesBeforeGreeting (scripted JSSE server that starts with TLS: download completes, no AUTH TLS, PROT P sent, data over TLS), RealFtpClientPassiveTest.retrieve_transferEndingWithRefusal_throwsTheReplysError, FtpErrorTest.fromReply_tlsSessionReuseRequired_mapsToUnsupported (Rebex, vsftpd and FileZilla Server wordings), and FtpUrlTest cases for which ftps:// URLs are implicit.
  • ./gradlew :library:ftp:jvmTest passes.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-23T13:58:50.891781Z 9755b9f PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 23, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@linroid
linroid force-pushed the fix/ftps-implicit-tls branch from 9755b9f to 48ebb43 Compare October 23, 2026 14:21
Base automatically changed from fix/ftp-passive-fallback to main October 23, 2026 14:49
ftps:// URLs default to port 990, where servers start with TLS (implicit
FTPS), but RealFtpClient sent AUTH TLS in plaintext and waited for a
greeting that never came: the download hung until killed. An ftps:// URL
on port 990 now opens its control connection with TLS and skips AUTH TLS,
as curl and FileZilla read it; other ports keep explicit FTPS.

Servers that require data connections to resume the control connection's
TLS session (Rebex, vsftpd's require_ssl_reuse, FileZilla Server) refuse
every transfer, which Ketch retried for minutes as a short transfer. A
transfer that ends with an error reply now throws it, and FtpError reads
the session-reuse refusals as KetchError.Unsupported with the reason.
@linroid
linroid force-pushed the fix/ftps-implicit-tls branch from 48ebb43 to 2aff8d4 Compare October 23, 2026 14:50
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 2 194 files   2 222 suites   57m 22s ⏱️
15 265 tests 14 997 ✅ 268 💤 0 ❌
18 616 runs  18 348 ✅ 268 💤 0 ❌

Results for commit 2aff8d4.

@linroid
linroid merged commit 449ac56 into main Oct 23, 2026
14 checks passed
@linroid
linroid deleted the fix/ftps-implicit-tls branch October 23, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant