NEXT UP previous
Next: archie

ftp

The ftp command is a user interface to the standard file transfer protocol. The purpose of ftp is to allow you to transfer files between a local machine and a remote machine, or vice versa. Running ftp is done as follows:

	$ ftp host.domain

where host domain is the fully qualified hostname of the required remote machine. The specification of the hostname on the command line is optional but if it is specified, ftp will attempt to make a connection to an ftp server on the remote machine. If no hostname is specified then ftp will issue a prompt and await user commands:

	$ ftp 
	ftp>

From the ftp> prompt, the open command followed by a hostname will attempt to connect to the given host.

Either way, when a successful connection is made with a remote machine, you will be required to login. If you have a user login on the remote machine you can use this account with ftp and supply its password. On the remote machine you will then have the read and write permissions of the login name you used. These permissions are used to determine what files you can download from the remote machine and to which directories you can upload files.

If you don't have a specific login account on the remote machine then many ftp setups have a special account that you can use instead. The login name for this account is called anonymous (hence the phrase anonymous ftp). When using this login name, you should enter your full e-mail address as the password.

If the remote system provides an anonymous ftp facility then using it will log you in to a special, publicly available, file read and write area. In particular, two directories are provided: pub, which contains all the files that the remote site is prepared to make available for public downloads, and incoming, into which you may upload files you wish to contribute to the remote site.

Once an ftp login to the remote site has been achieved you will receive an ftp> prompt from your local ftp program. You are then free to use any of the built-in ftp commands. You can get a list of the commands supported by using the help or ? command. You can also type help followed by the name of a specific command, which will give you a little detail about that particular command.

The commands you are most likely to want to use are:

A typical ftp session to retrieve a binary data file from a remote machine might appear as follows:

	$ ftp Hawklord
	Connected to Hawklord
	220 Hawklord FTP server
	Name (Hawklord:pc): anonymous
	331 Guest login ok, send your complete e-mail address as password
	Password:
	230 Guest login ok, access restrictions apply.
	Remote system type is UNIX.
	ftp> cd pub 
	250 CWD command successful. 
	ftp> ls
	200 PORT command successful.
	150 Opening ASCII mode data connection for /bin/ls. 
	total 114
	drwxr-xr-x	2 root	wheel	1024   Oct 31   23:45  .
	drwxr-xr-x	8 root	wheel	1024   Mar 28   1995   ..
	-rw-r--r--      1 root	root	14684  Oct 31   23:45  rog1
	-rw-r--r--      1 root	root	96547  Oct 31   23:45  rog2
	226 Transfer complete.
	ftp> binary
	200 Type set to I.
	ftp> hash
	Hash mark printing on (1024 bytes/hash mark). 
	ftp> get rog1
	200 PORT command successful.
	150 Opening BINARY mode data connection for rog1 (14684 bytes).
	##############
	226 Transfer complete.
	14684 bytes received in 0.0473 secs (3e+02 Kbytes/sec)
	ftp> quit
	221 Goodbye.
	$

This session starts by running ftp and requesting a connection to the hostname Hawklord. After some messages we receive an invitation to supply a login Name:. The contents of the brackets (Hawklord:pc) form the name that will be used if we Just press Enter at this point. However, we are going to perform an anonymous ftp transfer, so we login as anonymous. Next we get a request for a password with a prompt reminding us to supply our e-mail address. The password is not echoed so the characters don't appear, but in the example I typed:

	Password: chrisgibbs@geocities.com

Having successfully logged in to the remote system we change to the pub directory ind then list its contents. Deciding to download the file rog1 we set ftp up for binary file transfer and hash (#) mark displays on receipt of each full 1024-byte lata block. We then download the file and quit from ftp.

If you want to run an anonymous ftp service on your own machine then it needs little care to make sure your system remains secure. Some Linux distributions are supplied with anonymous ftp pre-installed and ready to run 'out of the box'. If you need to install it manually then you will need to create an ftp login in your etc/passwd file with a password of '*' and a login shell of /dev/false. This is to prevent ordinary logins using the ftp account. You will also need to set up a ftp home directory and a set of subdirectories, such as pub and incoming. The full details are a little involved but are well covered in the Linux NET-2-HOWTO document.


NEXT UP previous
Next: archie