SFTP: Transferring Files on the NSIT Server Cluster

NSIT operates harper, a multi-user Unix machine availble to the general campus community. If you need quick-start information on using Unix, please see Unix: Getting Your Feet Wet. For a general introduction to Unix, try our Unix command line tutorial or Unix documentation index

You can transfer files between the NSIT Server Cluster and other computers using the sftp (Secure FTP) utility which is part of the SSH suite. This program is available for just about any operating system; this document explains it's use on the command line implementation included in nearly all Unix/Linux distributions.

If you don't have a copy of sftp on your system, you can add it by installing SSH from either of these two locations:

Starting SFTP

The simplest way to invoke SFTP is in the form of:

sftp user@host.domain.topleveldomain

Where "user" is your account name on that machine, "host" is the machine name, "domain" is the domain name, and "topleveldomain" is the top level domain extension (.com, .edu, etc...). For example, replacing "CNetID" with your CNetID (NSIT account name), try:

sftp CNetID@harper.uchicago.edu

If you've never connected to that host before, you'll be prompted with a message stating that the authenticity of the host can not be established and you will be presented with their RSA fingerprint. If you choose to trust the host and connect, their RSA fingerprint will be added to SFTP's list of known hosts. If in the future the RSA fingerprint changes (in normal situations it should not change), you will see a similar warning.

Once you've accepted the host, or if you've previously added it to your lost of known hosts, you will be prompted for the password of the account your connecting with: in harper's case, that is your CNet password (the one you probably use to check your email). Once your password checks, the sftp session will be option, denoted by a prompt like this:

sftp>

Using SFTP

The first thing you'll want to do once your connected is to list all of the commands. In sftp this is a simple thing: just type "?" or help and press enter. You'll see sftp's simple and generally self-explanatory command set.

Moving Around

SFTP is designed to work as a simple shell; you can navigate the remote systems directly using familiar commands like ls, and cd. To get started, it's helpful to know where you are with pwd (print working directory):

sftp> pwd

Which on harper would return something like:

Remote working directory: /nfs/harper/ha0/CNetID

To view the contents of the directory, use the ls command, possibly with the -l and -a flags. To contact a new directory, use cd, then the directory path where you want to go. In either case, if you'd like to navigate your location instead of the remote one, use the pwd, ls, and cd commands, but with an l in front (for local). For example:

sftp> lpwd

Will return something like

Local working directory: /home/username

Downloading Files

Now that you are connected you can start downloading files. The syntax for getting a file is pretty simple: "get". The full syntax is actually:

get remote-path local-path

So, for example, to pick up a file named example.file from your current remote directory and place it in your current local directory, you'd simply enter:

get example.file

but if you wanted to grab the same file from a folder named testfolder and place it into /home on your system, it'd look like:

get testfolder/example.file /home

Now that you are connected to the remote host, the next step is to retrieve your file. To do this, issue theget command with the name of the file you wish to receive (including an absolute or relative pathname).

Suppose that you want to retrieve the file called "grub" in the /pub/recipes/ directory. (It is common for anonymous ftp sites to put all of their offerings under a single /pub directory.) You will first have to change to the /pub/recipes directory, and then retrieve grub. Here's how:

 ftp> cd /pub/recipes <Enter>
 250 CWD command successful.
 ftp> get grub <Enter>

You will get a response which looks something like this:

200 PORT Command OK.
 125 File transfer started correctly
 226 File transfer completed ok
 local: grub remote: grub
 639 bytes sent in .1 seconds (6.2 Kbytes/s)

Then you can close the connection and quit the program:

 ftp> close <Enter>
 221 Over and Out.
 ftp> quit <Enter>

Using ftp to transfer your own files

You can use ftp to transfer files from one system where you have an account to another system (where you also have an account). To retrieve (get) files from the NSIT Server Cluster while logged into some other machine, ftp to a Cluster machine (such as harper) then use your NSIT username (CNetID) and password (instead of "anonymous" and your email address). Then follow the same procedure as above (using the get command, or its variant mget for multiple files). To place (put) files in your home directory on the NSIT Server Cluster, use the put or mput commands.

For example, to copy your Statistics homework assignments from the NSIT Server Cluster to your own machine, "mycray.rh.uchicago.edu." You would login to the Cluster machine where your home directory is located, then ftp to "mycray.rh.uchicago.edu," and issue the following command:

ftp> mput stat* <Enter>

This would transfer all the files beginning with the pattern "stat" in your home directory to my cray. (The mput and mget commands use the asterisk as a "wildcard"--a letter that can stand for any number of characters.) Once you're finished, use the close and quit commands to end the ftp session.

Ftp command summary

Once you are in ftp, there are only a few basic commands to know:

cd
changes directory; works like the Unix command (see below)
ls
lists files, just like the Unix command; all options work (see below)
dir
lists files; can be more detailed than ls, and often works on systems which do not understand ls
bin
puts ftp in binary transfer mode; type this before transferring any files which are not strictly ASCII text (such as software, word processing files, sounds, etc.)
get
gets a specified file; i.e., copies it from other machine to yours
mget
multiple get; allows wildcards for matching groups of files
put
puts a specified file; i.e., copies it from your machine
mput
multiple put; allows wildcards for matching groups of files
close
disconnects your connection to the remote computer
quit
ends your ftp session

Although cd and ls usually work just the way they do on the Unix command line, they will behave a bit differently when you ftp to non-Unix systems on the Internet. For example, you may find that ls doesn't accept any of its usual options, or cd will not work with relative pathnames. Most of the time, though, they will work normally.

A note on binary transfer mode

The command summary above mentions that the bin command will invoke "binary transfer mode." By default, ftp transfers files in "ASCII mode," which should be used whenever you use ftp to transfer plain-text files (such as mail messages) across the network. When copying files that are not plain ASCII text, switch to binary mode before making the transfer. This includes executable programs, graphics, compressed or "zipped" file archives, or even Microsoft Word documents (which aren't considered "text" by the computer because of the formatting codes they contain).

Most of the time this distinction is academic, and you can often transfer ASCII files in binary mode without any serious problems. Every now and then, however, you may find yourself trying to retrieve a file from a system with quirks or incompatibilities which will produce gibberish if you use the wrong mode--so it is good to be in the habit of using the right transfer mode whenever you use ftp.

Further information

Within ftp on the NSIT Server Cluster, typing help in ftp will give you a list of available commands, and helpcommandname will give you help for a particular command.

For more information, see the online manual page: type man ftp at the Unix shell prompt.

Note that software to transfer files using the File Transfer Protocol also exists for several other kinds of machines. One FTP client for the Macintosh is Fetch (included in the NSIT Connectivity Package for Macintosh); among the FTP clients for Windows is WS-FTP (included in the NSIT Connectivity Package for Windows).

Last updated: 10/03/06