This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ftplib needs a rewrite to use bytes/buffers
Type: Stage:
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, brett.cannon, giampaolo.rodola, vstinner
Priority: normal Keywords:

Created on 2007-10-08 20:12 by brett.cannon, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg56281 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-10-08 20:12
For instance, ftplib.FTP reads from sockets using socket.makefile(), but
in text mode.  That's bad when the data could be in the format of ASCII
or binary data.
msg73553 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2008-09-22 02:28
Actually the 'r' flag is used against the control connection which is
not supposed to receive any "binary" data and in FTP.retrlines method
which is supposed to retrieve data in line mode.
msg75007 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-20 21:17
So can we close this?
msg75052 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-10-21 22:18
Function result type should be the same of the connection is in text 
mode or binary mode. As far as I remember, the text mode converts the 
newline byte sequence, not the charset. A text file could be stored as 
latin-1, utf-8, koi-8 or anything else. Am I wrong?

ftplib should use byte strings (as I did for POP3, IMAP4 or some other 
libraries) because the FTP protocol doesn't send the charset.
msg75056 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-10-21 22:57
- retrbinary() and storbinary() uses bytes (byte strings)
 - retrlines() and storlines() uses str (unicode strings) with 
charset=self.encoding
 - command is an unicode string converted to byte string with 
charset=self.encoding

So it's already possible to receive/send raw bytes, and forget my 
previous message.

I see a potential but minor problem: if the server is running a POSIX 
OS, it's not possible to open / rename / unlink a file with an invalid 
name. ftp might allow bytes filename, but I prefer to leave ftplib 
unchanged. If your FTP server is broken, fix your file system, fix your 
configuration or use an old FTP client to fix the problem.
msg75360 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-10-30 09:23
> So can we close this?

Yes: retrbinary() and storbinary() can be used to get/send bytes.

Reopen the issue (or open another one) if we miss another problem.
History
Date User Action Args
2022-04-11 14:56:27adminsetgithub: 45589
2008-10-30 09:23:52vstinnersetstatus: open -> closed
messages: + msg75360
2008-10-21 22:57:00vstinnersetmessages: + msg75056
2008-10-21 22:18:26vstinnersetnosy: + vstinner
messages: + msg75052
2008-10-20 21:17:07benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg75007
2008-09-22 02:28:05giampaolo.rodolasetmessages: + msg73553
2008-03-19 21:16:55giampaolo.rodolasetnosy: + giampaolo.rodola
2008-01-06 22:29:45adminsetkeywords: - py3k
versions: Python 3.0
2007-10-08 20:12:04brett.cannoncreate