Foundations of Python Network Programming

(WallPaper) #1
317

Chapter 17

FTP


File Transfer Protocol (FTP) was once among the most widely used protocols on the Internet, invoked whenever a
user wanted to transfer files between Internet-connected computers. Alas, the protocol has seen better days, and
today a better alternative exists for every one of its major roles.
There were four primary activities that FTP once powered. The first and major use of FTP was for file downloads.
Lists of “anonymous” FTP servers that allowed public access were circulated, and users connected to retrieve
documents, the source code to new programs, and media like images or movies. (You logged in to them with the
username “anonymous” or “ftp,” and then—out of politeness, so they would know who was using their bandwidth—
you typed your e-mail address as the password.) FTP was always the protocol of choice when files needed to
be moved between computer accounts, because trying to transfer large files with Telnet clients was often a dicey
proposition.
Second, FTP was often jury-rigged to provide for anonymous upload. Many organizations wanted outsiders to be
able to submit documents or files, and their solution was to set up FTP servers that allowed files to be written into a
directory whose contents could not, then, be listed back again. That way, users could not see (and hopefully could not
guess!) the names of the files that other users had just submitted and get to them before the site administrators did.
Third, the protocol was often in use to support the synchronization of entire trees of files between computer
accounts. By using a client that provided for recursive FTP operations, users could push entire directory trees from
one of their accounts to another, and server administrators could clone or install new services without having to
rebuild them from scratch on a new machine. When using FTP like this, users were generally not aware of how the
actual protocol worked or of the many separate commands needed to transfer so many different files: instead, they
clicked a button and a large batch operation would run and then complete the process.
Fourth, and finally, FTP was used for its original purpose: interactive, full-fledged file management. The early FTP
clients presented a command-line prompt that felt something like a Unix shell account itself, and—as I will explain—
the protocol borrows from shell accounts both the idea of a “current working directory” and of a cd command to move
from one directory to another. Later clients mimicked the idea of a Mac-like interface, with folders and files drawn on
the computer screen. But in either case, in the activity of file-system browsing, the full capabilities of FTP finally came
into play: it supported not only the operations of listing directories and uploading and downloading files, but also of
creating and deleting directories, adjusting file permissions, and renaming files.


What to Use Instead of FTP


Today, there are better alternatives than the FTP protocol for pretty much anything you could want to do with it.
Occasionally, you will still see URLs that start with ftp://, but they are becoming quite rare. This chapter will be
useful if you have a legacy system and you need to speak FTP from your Python program or because you want to learn
more about file transfer protocols in general and FTP is a good, historical place to start.
The biggest problem with the protocol is its lack of security: not only files, but usernames and passwords are sent
completely in the clear and can be viewed by anyone observing network traffic.

Free download pdf