Hi! I think I’ve found a discrepancy in the documentation in Python’s ftplib.

A comment on line 75 claims that ftplib supports \r, \n, and \r\n line endings

# Line terminators (we always output CRLF, but accept any of CRLF, CR, LF)

but after attempting to use it to read a 2 MB file with \r line endings off of an FTP server, this does not appear to be the case. The entire file is read out as a single “line” (after increasing the size of FTP.maxline). It looks like this is intentional, as the the implementation of FTP.retrlines() and FTP_TLS.retrlines() only strips \n and \r\n (snippet from line 452)

if line[-2:] == CRLF:    line = line[:-2]
elif line[-1:] == '\n':
    line = line[:-1]
callback(line)

Am I missing something? Or just interpreting the documentation wrong? I know this is not a common occurrence (esp. since RFC 959 states that ASCII line endings should be \r\n), but it seems confusing, and doesn’t mesh with Python’s generally excellent universal newline support.

This seems to be the case with the versions of ftplib in Ubuntu 18.04.2’s distribution of Python 2.7.15+ and Python 3.6.8. The FTP server in question is run off of an unknown RTOS on a Zumbach ODAC-14XY laser micrometer. I can provide an example of the file in question if required.

--
Cheers,

Patrick Dunham
Scale-Up Engineer