Notice: Undefined index: PATH_INFO in /usr/local/www/ngc/phpsubs on line 61
Transfering Files from Your UNIX Account with FTP
Notice: Undefined variable: Date in /usr/local/www/ngc/shell/ftp.phtml on line 8

Transfering Files from Your UNIX Account with FTP

Table of contents
The Web
Usenet news IRC
File transfer
The Internet is full of FTP servers, computers that store large archives of files that are available for download. Most FTP servers allow anyone to download files, using a system called anonymous FTP, which means that you type anonymous as your username when you log in to the FTP server.

To download files from an FTP server (or upload files to an FTP server, if you have permission to do so), you run an FTP program. The UNIX FTP program is called ftp, as you may already have guessed.

When downloading files, you've got to connect to the FTP server that stores the file, tell the FTP program which file you want, and indicate whether the file contains text ("ASCII") or something else ("BINARY"). FTP needs to know this because different types of computer systems store text files in different ways; specifically, they use different characters to indicate the end of each line of text. When you transfer a text file, FTP adjusts the line-ending characters for the computer system you are copying the files to. When you transfer any other kind of file, FTP doesn't fool with the contents of the file at all.

Remember that if you are calling into a UNIX account by using a terminal program on your PC or Macintosh, it takes two steps to get a file from an FTP server to your own computer. First, you use FTP to copy the files from the FTP server to your Internet provider's computer. Second, you still have to download it to your computer.

How hard can it be to copy a file from one place to another?

It's relatively simple to copy a file from one place to another (but don't forget -- computers are involved). Here's how it works: Log in to the other computer for FTP and tell it what you want to copy and where you want it copied to. Here's how to use the ftp program to download a file (that is, to copy a file from the FTP server to your computer).

Run the ftp program, by typing the name of the FTP server on the command line. To connect to the FTP server, for example, type this line:


You see a bunch of messages, confirming that you are connected and asking for your account name:

Connected to
220 FTP server (Version wu-2.1b(1) Fri Jun 25 14:40:33 CDT 1993) ready.

Type your username on the FTP server. If you don't have one, type anonymous. If you log in as anonymous, you see a message like this:

331 Guest login ok, send your complete e-mail address as password.

Next, the FTP server wants to know your password. If you typed a username, type your password. If you logged in as anonymous, type your e-mail address as your password. You see messages from the FTP server telling you what the rules of the server are, and then you see the ftp> prompt, which means that the FTP server is waiting for your command.

Go to the directory on the FTP server that contains the file you want, using the cd command, like this (this command moves to the docfiles directory):

cd docfiles

To see the files in the current directory, type dir. You see a directory listing with filenames and sizes, like this:

200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
total 23
drwxrwxr-x 19 root archive 512 Jun 24 12:09 doc
drwxrwxr-x 5 root archive 512 May 18 08:14 edu
drwxr-xr-x 31 root wheel 512 Jul 12 10:37 systems
drwxr-xr-x 3 root archive 512 Jun 25 1992 vendorware
... lots of other stuff ...
226 Transfer complete.
1341 bytes received in 0.77 seconds (1.7 Kbytes/s)

When you find the file you want, tell the FTP server what kind of file it is. For text files, type ascii. For all other files, type binary or image.

Use the get command to copy it to your computer. For example, type:


If you are using a UNIX shell account, the get command copies the file to your provider's computer, not to your own computer. You see messages like this:

150 Opening ASCII mode data connection for README (12686 bytes).
226 Transfer complete.
local: README remote: README
12979 bytes received in 28 seconds (0.44 Kbytes/s)

When you finish copying files, log off the FTP server, by using the quit command. You see a friendly message:

221 Goodbye.

That's basically how FTP works, but of course you need to know about 400 other odds and ends to use FTP effectively.

The first directory you see on the FTP server may contain file with names such as or index.txt. It's a good idea to download and view these files before continuing.

The directory thicket

You use the dir command to see what's in a directory. Most FTP servers run an operating system called UNIX. When you use the FTP dir command, you see a standard UNIX directory listing, in which the first letter on the line tells you whether something is a file or a directory. d means that it's a directory -- anything else is a file.

If you want to see some but not all of the files in the current directory, you can type a filename after the dir, and you can use * in the filename to match an character or characters. For example, to see a listing of files that begin with z, you type:

dir z*

If you see any directories in the current directory, the cd command changes directories. It changes the current directory on the FTP server but doesn't affect the current directory on your UNIX system. You can also change the directory on your own computer, using the lcd command. (You might expect cd to change directories correspondingly on both machines, but it doesn't.)

To move up to the directory that contains the current directory (the parent directory, as they say), type:

cd ..

What's in a name?

You can change the name of a file when you download it. Because filenames in UNIX can be longer than they can on pre-Windows 95 PCs, you may have to use a different name for the file when you download it. To store the file by using a different name from the one it has on the FTP server, type the name you want to use at the end of the get command, like this:

get rose-photograph rose2.gif

This command downloads the file named rose-photograph and names it rose2.gif.

Grabbing a buncha files

Suppose that you want to get a bunch of the files that begin with ru. In that case, you can use the mget (which stands for multiple GET) command to retrieve them. The names you type after mget can be either plain filenames or wildcard patterns that match a bunch of filenames. For each matching name, FTP asks whether you want to retrieve that file, as in the following:

ftp> mget ru*
mget ruby? n
mget ruby2? n
mget ruger_pistol? n
mget rugfur01? n
mget rush? y
200 PORT command successful.
150 Opening BINARY mode data connection for rush (18257 bytes).
226 Transfer complete.
local: rush remote: rush
18257 bytes received in 16 seconds (1.1 Kbytes/s)
mget rush01? y
200 PORT command successful.
150 Opening BINARY mode data connection for rush01 (205738 bytes).
local: rush01 remote: rush01
205738 bytes received in 200.7 seconds (1.2 Kbytes/s)
mget rush02?

Note: If you find that mget matches more files than you expected, you can stop it with the usual interrupt character for your system -- typically Ctrl-C or Delete. You can even interrupt in the middle of a transfer if a file takes longer to transfer than you want to wait.

This game of 20 Questions is OK for three or four files, but it can get darned tedious if you want to copy a bunch of them. Fortunately, you also can do an express mget, which doesn't ask any questions and enables you to find exactly the files you want. Suppose that you use the dir command to see information about a bunch of files you might want to download:

ftp> dir 92-1*
200 PORT command successful.
150 Opening ASCII mode data connection for 92-1*.
-rw-rw-ró 1 johnl staff 123728 Jul 1 20:30 92-10.gz
-rw-rw-ró 1 johnl staff 113523 Jul 1 20:30 92-11.gz
-rw-rw-ró 1 johnl staff 106290 Jul 1 20:30 92-12.gz
226 Transfer complete.
remote: 92-1*
192 bytes received in 0.12 seconds (1.5 Kbytes/s)

Now suppose that you want all those 92-1 files and don't feel like hammering on the y key to tell FTP to get all the files. Use the prompt command, which tells FTP not to ask any questions in mget but to just do it:

ftp> prompt
Interactive mode off.
ftp> mget 92-1*
200 PORT command successful.
150 Opening BINARY mode data connection for 92-10.gz (123728 bytes).
226 Transfer complete.
local: 92-10.gz remote: 92-10.gz 123728 bytes received in 2.8 seconds (43 Kbytes/s)
200 PORT command successful.
150 Opening BINARY mode data connection for 92-11.gz (113523 bytes).
226 Transfer complete.
local: 92-11.gz remote: 92-11.gz 113523 bytes received in 3.3 seconds (34 Kbytes/s)
200 PORT command successful.
150 Opening BINARY mode data connection for 92-12.gz (106290 bytes).
226 Transfer complete.
local: 92-12.gz remote: 92-12.gz 106290 bytes received in 2.2 seconds (47 Kbytes/s)

About face!

OK, now you know how to retrieve files from other computers. How about copying the other way? It's just about the same procedure except that you use put rather than get. That is, you log on to the FTP server and use the cd and dir commands to find the directory to which you want to upload the file. Then you use put to copy the file to the FTP server, and quit to log off. Simplicity itself!

The following example shows how to copy a local file called rnr to a FTP server and rename the file on the server:

ftp> put rnr
200 PORT command successful.
150 Opening ASCII mode data connection for
226 Transfer complete.
local: rnr remote:
168 bytes sent in 0.014 seconds (12 Kbytes/s)

(As with get, if you want to use the same name when you make the copy, leave out the second name.) The mput command works just like the mget command does, only in the other direction. If you have a bunch of files whose names begin with uu and you want to copy most of them, issue the mput command, as in the following example:

ftp> mput uu*
mput uupick? y
200 PORT command successful.
150 Opening ASCII mode data connection for uupick.
226 Transfer complete.
local: uupick remote: uupick
156 bytes sent in 0.023 seconds (6.6 Kbytes/s)
mput uupoll? y
200 PORT command successful.
150 Opening ASCII mode data connection for uupoll.
226 Transfer complete.
local: uupoll remote: uupoll
200 bytes sent in 0.013 seconds (15 Kbytes/s)
mput uurn? n

(As with mget, you can use prompt to tell it to go ahead and not to ask any questions.)

Most systems have protections on their files and directories that limit where you can copy files. You generally can use FTP to put a file anywhere that you could create a file if you were logged in directly by using the same login name. If you're using anonymous FTP, you generally cannot put any files at all.

Other FTP shenanigans

A bunch of other file-manipulation commands are sometimes useful, as in the following example of the delete command:

delete somefile

This command deletes the file on the remote computer, assuming that the file permissions enable you to do so. The mdelete command deletes multiple files and works like mget and mput. The mkdir command makes a new directory on the remote system (again assuming that you have permissions to do so), as in the following example:

mkdir newdir

After you create a directory, you still have to use cd to change to that directory before you use put or mput to store files in it.

If you plan to do much file deleting, directory creating, and the like, it's usually much quicker to log in to the other system by using telnet to do your work and using the usual local commands.

Return to previous section

Internet Gurus Home Search This Site Our Books
Internet Gurus Central
"...For Dummies" is a registered trademark of Wiley Publishing, Inc.
© Copyright 1998-2011 I.E.C.C. Last update August 5, 2009.