SFTP Basic Commands
SSH File Transfer Protocol (also Secure File Transfer Protocol, or SFTP) is a network protocol that provides file access, file transfer, and file management over a secure channel, such as SSH.
Connect
Enter the username and remote hostname or IP address at the command prompt. Once authentication successful, you will see a shell with an sftp>
prompt.
[user@computer1 ~]$ sftp demo@192.168.1.2
demo@192.168.1.2's password:
Connected to demo@192.168.1.2.
sftp>
When using a SSH identity file (private key) for public key authentication:
sftp -i keypair.pem demo@192.168.1.2
Check current directory
lpwd – print the current directory on your local system
sftp> lpwd
Local working directory: /home/livia
sftp>
pwd – print the current directory on the remote server
sftp> pwd
Remote working directory: /home/demo
sftp>
List files
lls – list the files in the current directory on your local system
sftp> lls
Desktop lab py3-venv
Documents mail R
dotfiles myserverfile snap
Downloads node_modules Videos
sftp>
ls – list the files in the current directory on the remote server
sftp> ls
Desktop Documents Downloads Music
Pictures Videos
sftp>
Download files
get – download one file from remote server
sftp> get remote_file.pem
Fetching /home/demo/remote_file.pem to remote_file.pem
/home/demo 100% 1696 906.8KB/s 00:00
sftp>
mget – download multiple files from remote server
sftp> mget *.csv
Fetching /home/demo/user1_accessKeys.csv to user1_accessKeys.csv
/home/demo 100% 96 73.1KB/s 00:00
Fetching /home/demo/user2_accessKeys.csv to user2_accessKeys.csv
/home/demo 100% 96 67.0KB/s 00:00
sftp>
Upload files
put – upload one file from local computer to the remote server
sftp> put local_file.pem
Uploading local_file.pem to /home/demo/local_file.pem
local_fil 100% 1696 75.2KB/s 00:00
sftp>
mput – upload multiple files from local computer to the remote server
sftp> mput *.csv
Uploading user1_accessKeys.csv to /home/demo/user1_accessKeys.csv
user1_acce 100% 96 129.7KB/s 00:00
Uploading user2_accessKeys.csv to /home/demo/user2_accessKeys.csv
user2_acce 100% 96 132.1KB/s 00:00
sftp>
Change directory
lcd – change the current directory on your local system
sftp> lpwd
Local working directory: /home/livia
sftp> lcd lab/
sftp> lpwd
Local working directory: /home/livia/lab
sftp>
cd – change the current directory on the remote server
sftp> pwd
Remote working directory: /home/demo
sftp> cd Documents/
sftp> pwd
Remote working directory: /home/demo/Documents
sftp>
Exit
exit – exit the remote server sftp session
sftp>
sftp> exit
[user@computer1 ~]$
More about SFTP can be found at the manual page.