Skip to content

Properly parse multi-line FTP responses#3262

Closed
nnposter wants to merge 1 commit intonmap:masterfrom
nnposter:ftp-readreply
Closed

Properly parse multi-line FTP responses#3262
nnposter wants to merge 1 commit intonmap:masterfrom
nnposter:ftp-readreply

Conversation

@nnposter
Copy link
Copy Markdown

@nnposter nnposter commented Jan 4, 2026

The current behavior of ftp.read_reply() is to treat any response line that starts with three decimal digits and a space as the end of a multi-line response. However, this is not the correct behavior according to RFC 959, section 4.2:

Thus the format for multi-line replies is that the first line will begin with the exact required reply code, followed immediately by a Hyphen, "-" (also known as Minus), followed by text. The last line will begin with the same code, followed immediately by Space , optionally some text, and the Telnet end-of-line code.
...
The user-process then simply needs to search for the second occurrence of the same reply code, followed by (Space), at the beginning of a line, and ignore all intermediary lines. If an intermediary line begins with a 3-digit number, the Server must pad the front to avoid confusion.

This patch updates ftp.read_reply() to comply with the RFC. It will be merged in after February 1 unless concerns are raised.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant