Still more FTPing
So last week in our discussion of FTP we tried to get to the point where we send and receive files but we got sidetracked by transfer modes. This week we really will get to move files around.
To recapitulate: We have connected, authenticated (commands USER and PASS), changed directories (CWD), set the translation type to ASCII (TYPE A), listed the current directory (LIST), set the translation type to image (TYPE I), and set the transfer to be passive (PASV, specifying that we will access a server-defined port for the data transfer -remember that commands are issued on port 21 and data transfers are performed on some other port specified by the FTP client or the FTP server).
We've left the transmission mode to default to stream (the command we won't send would be MODE S) and so now, let's transfer a file:
RETR myfile.zip
150 Opening image mode data connection for myfile.zip.
226 Transfer complete.
On our end, after the command and before the 226 response, we had to open the server port, start reading data from the port and store the data in a file. As we discussed last week, in stream mode the end of a file is signified by the stream ending - the server closes the connection and we assume that signifies the end of file, unless of course the transfer got garbled. Usually this is not a problem, but if your connection suffers packet loss you might need to use block or compressed mode if the client and server support them.
Sending a file is much the same except we use the STOR command:
STOR myfile.zip
150 Opening image mode data connection for myfile.zip.
226 Transfer complete.
If you want to stop the current file transfer, you just need to issue an abort (ABOR) command. Then there is the no operation (NOOP) command that tells the server the client is still alive. Most FTP clients use this command to keep the current session alive (that is, so you don't have to keep logging on).
Manipulating files is pretty straightforward: Changing file names is done with the "rename from" and "rename to" commands (the latter must immediately follow the former), thus:
RNFR myfile.zip
350 File exists, ready for destination name
RNTO myfile2.zip
250 RNTO command successful.
Other useful commands are delete (DELE
Finally, if you want to end your session with the server, you should issue the logout (QUIT) command (although if there's no data transfer in progress, simply dropping the connection will have the same effect but faster).
FTP is a reasonably straightforward protocol, and if you want to get deeper into FTP technology check out the FTP Protocol Resource Center
Transfer your thoughts to gearhead@gibbs.com
RELATED LINKS
Comments and suggestions to gh@gibbs.com.
Gibbs Forum
The place to discuss Gibbs's columns.
Check out this week's edition of
Backspin for more musings from Gibbs.
Part 1: Intro to
FTP
Network World, 7/23/01.
Part 2: The connection to the
server is made
Network World, 7/30/01.
Part 3: Connection
modes
Network World, 8/6/01.
Part 5: FTP server security
Network World, 8/20/01.
Part 6: SITE and SYST
Network World, 8/27/01.
Comments and suggestions to gh@gibbs.com.
Gibbs Forum
The place to discuss Gibbs's columns.
Check out this week's edition of
Backspin for more musings from Gibbs.

