4.2. SSH file transfer (SFTP)

As opposed to SCP, which only allows for single-command transfers, SFTP provides the user with a simple interactive shell for transferring files between your machine and another computer (most likely a server). In addition to providing support for uploading and downloading files, the SFTP shell allows for limited navigation through and manipulation of the local and remote file systems.

Start SFTP by typing sftp username@server_name at the prompt, filling in the appropriate values for your username and the server's name. The commands that you'll most likely need are listed in Table 4.1, “SSH file transfer (SFTP) commands”.

[Note]Note

SFTP commands look a lot like those discussed in Section 3.2, “Navigating the file system” and Section 3.3, “Manipulating the file system”, but commands to be run on the local machine (the one in front of you) have an l prefix (such as lls), while commands to be run on the remote machine (the one you're connecting to) don't have an l prefix (such as ls).

As far as I can tell, command history and command completion (discussed in Section 3.1, “Features of the shell”) are not available in SFTP. In addition, you cannot transfer entire directories through SFTP; you must compress them first into a tarball[36] and then transfer the tarball.

Example 4.1. Using SSH file transfer (SFTP)

sftp jg18@grid.cec.wustl.edu

[Note that not even asterisks will be displayed on the screen as you type your password.]

You'll then have a prompt like sftp> at which you can type commands.


Table 4.1. SSH file transfer (SFTP) commands

CategoryCommandAction
Basic SFTP Commands---
~help or ?View list of SFTP commands
~exit or quitExit SFTP
Working with File Systems---
~

(l)cd dir_name

Change directory on remote (local) machine
~

(l)ls [path]

List remote (local) directory contents
~

(l)mkdir dir_name

Create remote (local) directory
~

(l)pwd

Print name of working remote (local) directory
~

rename old_name new_name

Rename remote file or directory
~

rm file

(there is no lrm)
Remove remote file
~

rmdir dir_name

(there is no lrmdir)
Remove remote empty directory
Downloading and Uploading---
~

get remote_path [local_path]

Download from remote_path to working local directory [to local_path instead]
~

put local_path [remote_path]

Upload from local_path to working remote directory [to remote_path instead]
Other Commands---
~

!some_command

Execute some_command on local machine




Back to Guide main page