UC San Diego SearchMenu

SFTP - Secure File Transfer Protocol

'Sftp' is a secure version of the File Transfer Protocol (ftp). It uses FTP commands to transfer files securely between accounts, whether the accounts are on the same machine or on different machines, including your home computer, if it is properly configured.

List of SFTP Commands

To transfer a file you must know the machine name (e.g. mi5.ucsd.edu), and the name and password of the account with which you want to copy files.

Getting started with sftp:

Let's say you were on your account "jbond" and you wanted to transfer a file to an account drno on mi5.ucsd.edu. First, you should start sftp and tell it to which username and machine you want to hook up:

   % sftp drno@mi5.ucsd.edu
       

If this is the first time you have connected to the remote machine, mi5.ucsd.edu, a security warning message will be displayed:

   Connecting to mi5.ucsd.edu...
        The authenticity of host 'mi5.ucsd.edu (127.0.0.1)' can't be established.
        RSA key fingerprint is e4:16:3a:3f:69:b6:37:69:69:ca:bb:a6:33:fa:47:ac.
        Are you sure you want to continue connecting (yes/no)?
       

Type 'yes', and hit return. The remote machine will warn you that it now regards mi5.ucsd.edu as authentic, and then asks you for drno's password.

   Warning: Permanently added 'mi5.ucsd.edu' (RSA) to the list of known hosts.
        drno@mi5.ucsd.edu's password: 
       

If the account and password are correct, then the sftp prompt ( sftp> ) will appear:

   sftp>
       
How to get a single file from the remote account: 

To copy a file from the remote account to your original acount, use the "get" command followed by the name of the file you want to copy:

   sftp> get martini.txt
       
How to put a single file into the remote account:

To copy a file from your original account into the remote account, use the "put" command followed by the name of the file you want to copy:

   sftp> put shaken-not-stirred.txt

       
Some other useful sftp commands:

You are initially logged into the home directory of the remote account. It is possible to change to a different directory on the remote account using the "cd" command, just like in Unix:

   sftp> cd mydirectory
       

The "ls" command may be used to list the contents of the current directory on the remote machine.

   sftp> ls

       

Alternatively, "ls -l" can be used to obtain a more detailed listing, showing the file's access privilages, size, and the date it was last modified.

A list of sftp commands is available within ftp by typing the word "help" or a question mark (?) at the prompt:

   sftp> help
       

To exit the ftp program, type the command "quit" at the ftp prompt.

   sftp> quit
        %
       
Copying multiple files

To copy multiple files, use wildcard characters to specify many files. A 'wildcard' character is a punctation mark that represents any character, or any number of any characters. An asterisk '*' represents any number of any characters, and a question mark '?' represents one of any character.

   sftp> get *
       
Additional information:

For more information on sftp, see the manual page for sftp:

   % man sftp
       

List of SFTP Commands

While the version of SFTP that you are using will vary from machine to machine, here are some of the common commands, along with a brief definition

Commands:
cd path C hange remote directory to 'path'
lcd path Change local directory to 'path'
chgrp grp path Change group of file 'path' to 'grp'
chmod mode path Change permissions of file 'path' to 'mode'
chown own path Change owner of file 'path' to 'own'
help Display this help text
get remote-path [local-path] Download file
lls [ls-options [path]] Display local directory listing
ln oldpath newpath Symlink remote file
lmkdir path Create local directory
lpwd Print local working directory
ls [path] Display remote directory listing
lumask umask Set local umask to 'umask'
mkdir path Create remote directory
put local-path [remote-path] Upload file
pwd Display remote working directory
exit Quit sftp
quit Quit sftp
rename oldpath newpath Rename remote file
rmdir path Remove remote directory
rm path Delete remote file
symlink oldpath newpath Symlink remote file
version Show SFTP version
!command Execute 'command' in local shell
! Escape to local shell
? Synonym for help