Breadcrumbs 
Learning >> Documentation >> Internet >> FTP
 
Recent News
We Want You!
Come and get involved! (And Christmas Party!
[ more ]
Make your own Xbox games!
Learn to make Xbox 360 games
[ more ]
New Committee
A new committee has been appointed.
[ more ]
FTP
FTP

This will cover both the startup options for ftp and the commands available for use once its started. We will use the HeaNET ftp server for the purpose of demonstrating the use of the interactive mode. ftp is the user interface to the File Transfer Protocol standard created by ARPANET. It allows users to transfer files to and from a remote network site and is currently the one of most widely used methods for file transfer on the internet. Its used extensively by the open source community as a way of distributing their applications and also is used to provide CD images for most Linux distros.

First we'll cover the basic startup of an FTP connection using ftp, then using HeaNET's ftp server which hosts numerous mirrors (a mirror is a replica of the ftp site that contains the original works) for the open source community, we'll demonstrate how to use the most common interactive commands. For a complete listing of both the options for the ftp program and the interactive commands available once started see the man pages using 'man ftp'

Basic startup options
-i : this disables the interactive promting so that during multiple file transfers you are not prompted to approve the download of each file.
-t : enables packet tracing.
-v : verbose option, outputa all responses from the remote server.

In general you will just use the standard startup without any options. So now we're going to connect to the HeaNET ftp server.

$ ftp ftp.heanet.ie
Connected to ftp.heanet.ie.
220- Welcome to the Irish National Information Server FTP site.
220- All connections are logged; if this is disagreeable, please
220- disconnect now.
220-
220- This is a 6 Terabyte server with Gigabit access to the
220- HEAnet backbone.
220-
220- This is a European mirror. If you are in the USA, please
220- use a mirror closer to home.
220-
220 ftp.heanet.ie FTP server ready.
500 'AUTH GSSAPI': command not understood.
500 'AUTH KERBEROS_V4': command not understood.
KERBEROS_V4 rejected as an authentication type
Name (ftp.heanet.ie:dara): anonymous
331 Guest login ok, type your name as password.
Password: name
230 Guest login ok, access restrictions apply.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

Output you receive should be the same provided the admins don't add a few extra Terabytes in the mean time. Username anonymous is the default so you can just press return at this point. For a password enter in your name, which will not be displayed as you enter, normally this will request an email address but its up to you what you want to enter. Once complete you should now be in the interactive shell of ftp identified by the prompt ftp>Anonymous accounts only allow you to download, but since you can use sftp to connect to frink we'll cover the upload commands as well.

Basic commands in interactive mode
ascii : Sets transfer mode to ascii, should be used for any type of text file. html, php, etc
binary : Sets transfer mode to binary, used for data files, compressed files, .tar, .gz, .bz2, .zip etc.
hash : Toggles display of hash file for every 1KB of data transfered. Useful as a transfer guide.
prompt : Toggles whether your prompted during multiple file transfers. It on forces you to approve each retreive/upload
cd [directory] : Change to directory on remote machine, otherwise displays the current directory if left blank.
lcd [directory] : Change to directory on local machine, otherwise goes to the user home directory if left blank.
pwd : Prints the current working directory on the remote machine.
dir [remote-directory] [local-file] : Lists the contents of remote-directory optionally senting the output to [local-file] if specified, otherwise lists the connects of the current remote directory.
ls : Exactly the same as dir, except that the server will include any system-dependant output in the results. Most will display output equivalent to 'ls -l'
get remote-file [local-file] : Retreives the remote-file and stores it in the local current directory. If local-file is given the file is renamed to it locally.
mget remote-files : Like get, but retreives a list of files. Supports use of wildcards and is the most commonly used command.
put local-file [remote-file] : Uploads local-file to the the current directory on the remote machine, renaming it to remote-file if given.
mput local-files : uploads the local-files to the current directory on the remote macghine. Supports use of wildcards
open host [port] : Establishs a connection to the host using the option parameter [port] as the port to connect to otherwise port 21 is used by default
disconnect : Disconnects from whatever host is currently connected and remains in ftp.
user user-name [password] : Identify yourself to the remote FTP server. Used after open if auto-login is disabled or the default username is not valid on the remote server.
bye : Terminates the FTP session with the remote machine and exits ftp.
quit : Symonym for bye
! : Escapes to a shell on the local machine, allows you to create directories and manipulate files on the local machine without having to exit ftp. Type quit to return to ftp.

For the purpose of this demonstration we will be transfering some archives, or .tar.gz extension files which are binary types. Since ascii is the default transfer mode we will switch to binary transfer mode, otherwise the files will be transfered incorrectly and be garbage when it comes to using them.

ftp> binary
200 Type set to I.

Actually usually you can leave this set to ascii when downloading from the HeaNET server to frink even for non text files. Ascii/binary transfer modes are actually only required for files when the server and client are using different Operating Systems. Once your using the same or similiar Operating System it makes no difference. And no we're not going to explain why here, it would take too long.

We're going to go and download putty. Well aware of it being available on the website as is, but its better to demonstrate with something small. Once you've done this you can go back and retreive some of the other free software from the server as well. First step is to change to the directory, enable hashes for the display and to disable the prompt initially.

ftp> cd /pub/putty/0.53b/x86
250 CWD command successful.

Now to enable the hashes so that you can get a visible indicator of the download taking place.

ftp> hash
Hash mark printing on (1024 bytes/hash mark).

If you type hash again for a second time it disables it and you get "Hash mark printing off." outputted.

For the putty executable we're going to leave the prompt mode on for the moment and then disable it later when using the multiple get command. Do an ls first to see whats in the directory, you'll a lot of files but once you get used to them you'll recognise whats to be downloaded.

ftp> ls
227 Entering Passive Mode (193,1,219,100,226,63)
150 Opening ASCII mode data connection for '/bin/ls'.
total 3776
-rw-r--r-- 1 1000 1000 4838 Feb 3 09:33 index.html
-rw-r--r-- 1 1000 1000 4838 Feb 3 09:33 index.html?D=A
Removed section to reduce length
-rw-r--r-- 1 1000 1000 1146210 Nov 12 2002 putty-0.53b-installer.exe
-rw-r--r-- 1 1000 1000 65 Nov 12 2002 putty-0.53b-installer.exe.DSA
-rw-r--r-- 1 1000 1000 152 Nov 12 2002 putty-0.53b-installer.exe.RSA
-rw-r--r-- 1 1000 1000 356352 Nov 12 2002 putty.exe
-rw-r--r-- 1 1000 1000 65 Nov 12 2002 putty.exe.DSA
-rw-r--r-- 1 1000 1000 152 Nov 12 2002 putty.exe.RSA
Removed section to reduce length
226 Transfer complete.

Now get putty.exe, when using get you need to specify the full filename.

ftp> get putty.exe
local: putty.exe remote: putty.exe
227 Entering Passive Mode (193,1,219,100,231,16)
150 Opening BINARY mode data connection for 'putty.exe' (356352 bytes).
################################################################# ################################################################# ################################################################# ################################################################# ################################################################# #######################

At this stage you might want to use the ! command and see where the file has been downloaded to. It's probably gone to your home directory so its suggested that you create a temporary directory called tmp and move the file into it using 'mv putty.exe tmp/', then once done, exit and you should be returned to the ftp prompt. Use the lcd command to change the local directory into the tmp directory you just created or whatever name you used. That way any further downloads will be into the tmp directory and not directly into whatever directory you were in when you started ftp.

ftp> lcd tmp

Next we're going to retreive a small number of files using mget, in this case you'll be prompted for each download. We'll then perform the same with the prompt disabled so that you can see when it can be useful.

ftp> mget putty.exe.*
mget putty.exe.DSA? y
227 Entering Passive Mode (193,1,219,100,155,177)
150 Opening BINARY mode data connection for 'putty.exe.DSA' (65 bytes).
#
226 Transfer complete.
65 bytes received in 0.06 seconds (1.1 Kbytes/s)
mget putty.exe.RSA? y
227 Entering Passive Mode (193,1,219,100,155,207)
150 Opening BINARY mode data connection for 'putty.exe.RSA' (152 bytes).
#
226 Transfer complete.
152 bytes received in 0.04 seconds (3.7 Kbytes/s)
ftp>

Now we turn off prompting.

ftp> prompt
Interactive mode off.

Now we proceed with the retrieval using the same command as before, except this time we won't be prompted.

ftp> mget putty.exe.*
local: putty.exe.DSA remote: putty.exe.DSA
227 Entering Passive Mode (193,1,219,100,158,106)
150 Opening BINARY mode data connection for 'putty.exe.DSA' (65 bytes).
#
226 Transfer complete.
65 bytes received in 0.03 seconds (2.1 Kbytes/s)
local: putty.exe.RSA remote: putty.exe.RSA
227 Entering Passive Mode (193,1,219,100,158,111)
150 Opening BINARY mode data connection for 'putty.exe.RSA' (152 bytes).
#
226 Transfer complete.
152 bytes received in 0.05 seconds (3 Kbytes/s)
ftp>

Be careful when running the mget command with prompting turned off since as you can see, there was no warning about overwriting the existing copies of the files. In most cases it won't matter to you, since it will be the same file so you won't care.

Tip: If you forget to turn off prompting before using the mget command, you can abort its use with CTRL+C which will just terminate the current command so that you can switch off prompting and then start the retreival again.