Next: C.5 Quitting FTP Up: C FTP Tutorial and Previous: C.3 Poking Around

# C.4 Downloading files

Before downloading files, there are a few things that you need to take care of.

- Turn on hash mark printing. Hash marks are printed to the screen as files are being transferred; they let you know how far along the transfer is, and that your connection hasn't hung up (so you don't sit for 20 minutes, thinking that you're still downloading a file). In general, a hash mark appears as a pound sign (`#`), and one is printed for every 1024 or 8192 bytes transferred, depending on your system.

  To turn on hash mark printing, give the command `hash`.

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

- Determine the type of file which you are downloading. As far as FTP is concerned, files come in two flavors: binary and text. Most of the files which you'll be downloading are binary files: that is, programs, compressed files, archive files, and so on. However, many files (such as `README`s and so on) are text files.

  Why does the file type matter? Only because on some systems (such as MS-DOS systems), certain characters in a text file, such as carriage returns, need to be converted so that the file will be readable. While transferring in binary mode, no conversion is done---the file is simply transferred byte after byte.

  The commands `bin` and `ascii` set the transfer mode to binary and text, respectively. When in doubt, always use binary mode to transfer files. If you try to transfer a binary file in text mode, you'll corrupt the file and it will be unusable. (This is one of the most common mistakes made when using FTP.) However, you can use text mode for plain text files (whose filenames often end in `.txt`).

  For our example, we're downloading the file `README`, which is most likely a text file, so we use the command

  `ftp> ascii
  200 Type set to A.
  ftp>`

- Set your local directory. Your local directory is the directory on your system where you want the downloaded files to end up. Whereas the `cd` command changes the remote directory (on the remote machine which you're FTPing to), the `lcd` command changes the local directory.

  For example, to set the local directory to `/home/db/mdw/tmp`, use the command

  `ftp> lcd /home/db/mdw/tmp
  Local directory now /home/db/mdw/tmp
  ftp>`

Now you're ready to actually download the file. The command

`get`

is used for this, where is the name of the file on the remote machine, and is the name that you wish to give the file on your local machine. The argument is optional; by default, the local filename is the same as the remote one. However, if for example you're downloading the file `README`, and you already have a `README` in your local directory, you'll want to give a different so that the first one isn't overwritten.

For our example, to download the file `README`, we simply use

`ftp> get README
200 PORT command successful.
150 ASCII data connection for README (128.84.181.1,4527) (1433 bytes).
#
226 ASCII Transfer complete.
local: README remote: README
1493 bytes received in 0.03 seconds (49 Kbytes/s)
ftp>`

Next: C.5 Quitting FTP Up: C FTP Tutorial and Previous: C.3 Poking Around