Topics Map > University of Chicago > IT Services > Applications, Operating Systems, & Devices

Unix - Using SFTP

This article explains how to use a secure file transfer protocol in Unix.

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.

Keywords:unix sftp secure file transfer protocol commands   Doc ID:15882
Owner:Larry T.Group:University of Chicago
Created:2010-11-30 18:00 CSTUpdated:2015-03-30 05:25 CST
Sites:University of Chicago, University of Chicago - Sandbox
Feedback:  0   0