FTP is used to transfer files to and from remote network sites. This can mean placing files on a disk in a PC in the next room, or retrieving files from a mainframe in Zambia16.2. A number of sites worldwide accept anonymous FTP (guest logins). This means anybody can ``anonymously'' obtain publicly-available files from the site. The contents of anonymous FTP archives range from source code and technical reports to meteorological weather maps.16.3
To initiate an FTP session with a remote host, type:
ftp host-spechost-spec can be an IP address (eg. 188.8.131.52), a short name (for local sites --- eg. charlie, munnari), or a full name (eg. tsx11.mit.edu).
FTP will attempt to connect to the machine you specified. This is sometimes impossible, due to any number of network problems I won't go into.16.4If FTP can connect, you'll be prompted for a username and password. Log in as you would normally, except the username and password will be your password on the remote machine.
If you don't have an account on the remote machine, you may be able to login anonymously. An anonymous account is not the same as a user account; it only allows browsing and downloading from public directories, and you probably can't upload.
To log in anonymously, type anonymous (ftp and guest may also work) at the ``Name:'' prompt, and your full e-mail address (your login name followed by ``@it.uts.edu.au'')16.5 at the ``Password:'' prompt16.6.
Connected to ultima. 220 ultima FTP server (SunOS 4.1) ready. Name (ultima:progsoc): anonymous 331 Guest login ok, send ident as password. Password: email@example.com 230 Guest login ok, access restrictions apply. ftp>
Once you've successfully logged in, you can use the following commands:
We should mention here, before we go much further, that FTP is part of the quaint set of traditional protocols from back when the internet was made up of just FTP, telnet, email and a few things that went ping just to keep the clocks in sync.16.8
The World Wide Web (HTTP protocol)16.9 is more recent and now far more prevalent. Things like FTP have survived in a limited kind of way. (If one of your friends seems to think telnet has survived, please set them straight before they log in again -- ``friends don't let friends use telnet'').
The point of all this is: all protocols where you send passwords around the place should now have encryption. All other protocols, where you just want to connect somewhere anonymously and grab something, don't need a password so they're OK too. So we have HTTP for clicking on links around the globe, and FTP for publically distributing great slabs of source code from sourceforge.net (for example).
So, what do you do if you really want to send or receive a file to/from an account with a login and password? Well you could turn your entire connection into a point-to-point encrypted tunnel (one of the features of ssh). One of the quicker-and-nastier approaches is scp, ``secure copy''.
ftoomsh:~ :1 > scp "public_html/*" firstname.lastname@example.org:webbackup
Unfortunately, scp doesn't resemble the behaviour of ftp, because it's based entirely on good old cp -- but here you'll see some of the features of the good old copy command you've probably not used before. Yes, there is an sftp tool, but it doesn't operate like ftp either. (And yes, you can use cp to transfer files across different accounts with passwords in the clear, but if I catch you doing that, I'll take your TFM away).
If you look at the command line above you'll see that there are strictly two arguments, separated by a space. This example has a file being uploaded from a local directory to a remote directory; if you want to download instead, just swap the two arguments around.
The source, of course, needs to have a filename after the (optional) directory -- the only reason there are quotes, is (and this will save you much frustration) because I have used a wildcard (the asterisk will copy all files). Notice that in both cases, the directories have no initial slash and therefore lie under the home directory: The first one because it is the working directory for scp, and the second because it is the default directory for that login.
The standard login@machine:path terminology applies. As long as you don't forget the at-sign, the colon and the quotes when necessary, and don't stick any spaces where they don't belong, then it should work. Remember, you don't need to specify a filename for the destination; any existent directory will do. tt scp can be a bit tricky to get working the first few times, because it hasn't got any interactivity like FTP. Study the command line and you'll get it.
On PCs, the same people who provided Windows with an ssh client, PuTTY, have provided an scp client. Use pscp.
This example session logs onto the UTS anonymous FTP server (ftp.uts) from charlie. First, ftp.uts is added to the .netrc file in the users home directory. This will automatically log the user in as anonymous and give their e-mail address as the password16.10.
charlie:~ :1 > cat >> ~/.netrc machine ftp.uts login anonymous passwd cthulhu@it ^D charlie:~ :2 > chmod 600 .netrc
Next, a session is opened to ftp.uts. Commands entered by the user are after the ftp prompt.
charlie:~ :3 >ftp ftp.uts Connected to sequoia.ccsd.uts.EDU.AU. 220 sequoia FTP server (Version 6.23 Wed Feb 24 14:10:37 EST 1993) ready. 331 Guest login ok, send e-mail address as password. 230-Welcome to ftp.uts.EDU.AU. at the University of Technology, Sydney. 230- 230 Guest login ok, access restrictions apply. ftp> cd Mirror 250-Welcome to the 'Mirror' directory. All of the files in this 250-directory are copied from other systems in order to make them 250-more accessible to users (such as yourself). 250- 250 CWD command successful. ftp> cd Linux 250-Welcome to the Linux FTP archive! 250- 250-Please read the file README 250- it was last modified on Sun Jan 10 20:06:00 1993 - 55 days ago 250 CWD command successful. 150 Opening ASCII mode data connection for README (3718 bytes).
The get command allows you to retrieve a file and pipe it into a command. The following retrieves the README file and pipes it through the more command, which will display it one page at a time. (Note: any commands to be carried out locally, such as more in the example below, must be enclosed in double quotes as below.)
ftp> get README "|more" 200 PORT command successful. local: |more remote: README 3838 bytes received in 2.5 seconds (1.5 Kbytes/s) ftp> cd binaries 250 CWD command successful. ftp> dir 200 PORT command successful. 150 Opening ASCII mode data connection for /bin/ls. total 10 -r--r--r-- 1 root wheel 0 Aug 8 1992 .notar drwxr-xr-x 2 root wheel 512 Jan 21 1991 compilers drwxr-xr-x 2 root wheel 512 Jan 21 1991 lib drwxr-xr-x 2 root wheel 512 Mar 1 13:19 usr.games 226 Transfer complete. 636 bytes received in 0.72 seconds (0.86 Kbytes/s) ftp> cd usr.games 250 CWD command successful. ftp> dir 200 PORT command successful. 150 Opening ASCII mode data connection for /bin/ls. total 3981 -r--r--r-- 1 root wheel 251437 May 7 1992 dungeon.tar.Z lrwxrwxrwx 1 root 1 34 Mar 1 13:19 rain.tar.Z -r--r--r-- 1 root wheel 444077 Apr 28 1992 rayshade406.tar.Z -r--r--r-- 1 root wheel 66551 Jun 3 1992 tetris-bin.tar.Z -r--r--r-- 1 root wheel 302325 Jul 25 1992 xgames.tar.Z -r--r--r-- 1 root wheel 1235607 Oct 30 01:57 xtank1.3f.tar.Z 226 Transfer complete. 1308 bytes received in 0.3 seconds (4.3 Kbytes/s)
The file xtank1.3f.tar.Z should be a compressed tar archive of the binaries for the xtank game (for the Linux operating system). Since it is compressed (and it contains binary data anyway) transfer mode is set to binary mode with the bin command before transferring the file.
If you regularly FTP to a particular machine from the Faculty network, you might want to create a .netrc entry to automate the logon procedure. The manual page for netrc(4) has more information on how to do this. Also look at the X front end to ftp --- ftptool. There's a newer, better FTP out there now --- ncftp. It has the unquestionably good quality of being able to start receiving a file from the packet you had got up to if a previous FTP session was interrupted. Again, look at the man page.
Back to table of contents