SFTP CheatSheet

How To Use SFTP to Securely Transfer Files with a Remote Server

SFTP stands for Secure File Transfer Protocol and it is used to transfer securely using SSH tunnel from client to server over internet. In this tutorial I will list all the commands that is required when working with sftp.

How to connect to SFTP?

Followings are some of the methods of authenticating to sftp server.

# Authenticate using username and password
sftp user@serverIpOrDomain

# Authentication using secure key
sftp -i ~/.ssh/private.key user@serverIpOrDomain

# Authentication using ssh key along with port
sftp -i ~/.ssh/private.key -P 1022 user@serverIpOrDomain

# Authenticate using ssh key and algorithm
sftp -o KexAlgorithms=diffie-hellman-group14-sha1 -i ~/.ssh/private.key -P 1022 user@serverIpOrDomain

# Authenticate and change to dir
sftp user@serverIpOrDomain:/home/data

SFTP show current dir

To check current client and remote directories following commands are used:

# print the current directory on your system

# print the current directory on the ftp server

SFTP FIle listing

To perform different listing operation following sftp commands are used:

# show remote/ftp server directory listing

# shows local/client directory listing

# show files by date in sorted desc
ls -hltr

SFTP upload/download files

To download/upload a file from client to server following are some of the commands:

# upload client/local file to server
put filename

# upload multiple files from local to remote
mput *.csv

# download file from remote to local/client
get filename

# download multiple files from remote to local/client
mget *.csv

# rename remote file
rename old.csv new.csv

SFTP create or change or remote directories

To change directory on remote or local server following commands are used:

# change dir on server
cd dir/

# change dir on local/client
lcd dir/

# create directory on remote
mkdir dir/

# create directory on local/client
lmkdir dir/

# remove remote files or dir
rm file.csv
rmdir dir/

# remove local/client files
lrm file.csv
lrmdir dir/

Exit SFTP Shell

To logout from sftp server you need either of following commands:

# logout current session

# or use following command