FTP v. ftplib
April 17, 2012 at 10:07 PM by Dr. Drang
Since I’m already complaining about Python, I might as well add my dislike of one other standard library: ftplib
. I don’t have any criticism of how the library works, I just don’t like the names given to many of the functions.
Here’s the thing: There are a set of commands defined by the FTP protocol that a client program sends to the server. These are three- or four-letter codes like
Command | Functions |
---|---|
CWD |
change working directory |
LIST |
list the contents of a directory |
DELE |
delete file |
RETR |
retrieve a file from the server |
STOR |
store a file on the server |
QUIT |
quit the session |
Command-line ftp client programs, like the ftp
that’s on your Macintosh, Linux, or Windows machine, use these commands to communicate with the server but not with the user. User commands tend to be more friendly and easier to remember:
Command | Functions |
---|---|
cd |
change directory |
dir or ls |
list the contents of a directory |
delete |
delete file |
get |
get a file from the server |
put |
put a file on the server |
quit or bye |
quit the session |
(OK, cd
isn’t the most friendly command, but it’s easy to remember because it’s the same command used by the shell.)
So which set of names does ftplib
use for its FTP methods? I’d rather it used the second set, because that’s what I’m more familiar with,1 but if it wanted to use the server commands, I could live with that, too. Maddeningly, uses a mixture:
Method | Functions |
---|---|
cwd() |
change directory |
dir() |
list the contents of a directory |
delete |
delete file |
retrlines() |
retrieve a file from the server (ASCII mode) |
retrbinary() |
retrieve a file from the server (binary mode) |
storlines() |
store a file on the server (ASCII mode) |
storbinary() |
store a file on the server (binary mode) |
quit() |
quit the session |
We see the echoes of CWD
, RETR
, and STOR
from the server command set, but also dir
and delete
from the user command set.
I’m sure that if I used ftplib
regularly, I’d get used to this set of names, but I don’t and I haven’t. A more consistent set of names—one way or the other—would make the library easier to use.
I also wish the distinction between ASCII and binary transfer was handled by a flag passed as an argument rather than by separate methods for each mode. That would allow the method names to match RETR
and STOR
better and would eliminate the rather silly lines
suffix.
-
Both from using command line
ftp
itself and from using theNet::FTP
Perl module, whose method names match the user-level names almost perfectly. ↩