In this guide, you will learn how to use the SFTP client in Linux for secure file transfers and remote file management.
SFTP (SSH File Transfer Protocol) runs over SSH and encrypts data, usernames, and passwords in transit. Unlike legacy FTP, it is designed for secure file movement over untrusted networks.
By the end, you will know how to:
- Connect to an SFTP server
- Navigate remote and local directories
- Upload and download single or multiple files
- Create, rename, and remove files/directories
- Check remote filesystem usage
- Use helpful built-in SFTP command help
Related Content
Prerequisites
To follow along, make sure you have:
- An SFTP server to connect to
- A valid username and password (or SSH private key)
- Network access to the SFTP host and SSH port (usually
22) - SFTP client installed (available by default on most Linux distributions)
1. Connect to an SFTP Server
Use this format:
Example:
1
| sftp sftpuser1@192.168.10.10
|
Example output:
1
2
3
4
5
6
7
8
9
| sftp sftpuser1@192.168.10.10
The authenticity of host '192.168.10.10 (192.168.10.10)' can't be established.
ECDSA key fingerprint is SHA256:99KvuL95zO2CQbC8X0Re/Q+cYrJgqQgzpf1leemnjmY.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.10.10' (ECDSA) to the list of known hosts.
sftpuser1@192.168.10.10's password:
Connected to 192.168.10.10.
sftp>
|
After connection, you are in the interactive SFTP shell (sftp>). Your remote start directory depends on server configuration (for example user home or chroot path).
You can also connect using a custom port:
1
| sftp -P 2222 sftpuser1@192.168.10.10
|
2. Check SFTP Version
Inside the SFTP prompt:
1
2
3
4
| sftp> version
SFTP protocol version 3
sftp>
|
3. Show Remote Working Directory (pwd)
Use pwd to print your current remote directory:
1
2
3
4
| sftp> pwd
Remote working directory: /sftpuser1
sftp>
|
4. Show Local Working Directory (lpwd)
Use lpwd to print your current local directory:
1
2
3
4
| sftp> lpwd
Local working directory: /home/ubuntu
sftp>
|
Change remote directories with cd:
1
2
3
| sftp> cd sftpuser1
sftp>
|
You can also change local directories with lcd:
1
2
3
| sftp> lcd /home/ubuntu/downloads
sftp> lpwd
Local working directory: /home/ubuntu/downloads
|
5. Upload Files to SFTP Server (put, mput)
Upload a file using one-line mode
1
| sftp {user}@{host}:{remote-path} <<< $'put {local-path}'
|
Example:
1
2
3
4
5
6
7
| sftp sftpuser1@127.0.0.1:/sftpuser1/ <<< $'put ./citizix.txt'
sftpuser1@127.0.0.1's password:
Connected to 127.0.0.1.
Changing to: /sftpuser1/
sftp> put ./citizix.txt
Uploading ./citizix.txt to /sftpuser1/citizix.txt
./citizix.txt
|
Upload from interactive SFTP shell
1
2
3
4
5
6
7
8
9
10
11
12
| sftp>
sftp> pwd
Remote working directory: /sftpuser1/datadir
sftp> ls
sftp> lls
citizix.txt snap tmp
sftp> put citizix.txt
Uploading citizix.txt to /sftpuser1/datadir/citizix.txt
citizix.txt 100% 32 25.8KB/s 00:00
sftp> ls
citizix.txt
sftp>
|
Upload multiple files with mput:
1
2
3
4
5
6
7
8
9
10
11
12
13
| sftp>
sftp> pwd
Remote working directory: /sftpuser1/data
sftp> ls
sftp> lls
data1 data2 data3
sftp> mput data[23]
Uploading data2 to /sftpuser1/data/data2
data2 100% 0 0.0KB/s 00:00
Uploading data3 to /sftpuser1/data/data3
data3 100% 0 0.0KB/s 00:00
sftp> ls
data2 data3
|
6. Download Files from SFTP Server (get, mget)
Download a file in one command
1
| sftp {user}@{remote-host}:{remote-file-name} {local-file-name}
|
Example:
1
2
3
4
5
6
| sftp sftpuser1@127.0.0.1:/sftpuser1/citizix.txt .
sftpuser1@127.0.0.1's password:
Connected to 127.0.0.1.
Fetching /sftpuser1/citizix.txt to ./citizix.txt
/sftpuser1/citizix.txt 100% 32 26.7KB/s 00:00
|
Download from interactive session
1
2
3
4
5
6
7
8
9
| sftp>
sftp> ls
data2 data3
sftp> lls
sftp> get data2
Fetching /sftpuser1/data/data2 to data2
sftp> lls
data2
sftp>
|
Download multiple files with mget:
1
2
3
4
5
6
7
8
9
10
| sftp>
sftp> ls
data2 data3
sftp> lls
sftp> mget data*
Fetching /sftpuser1/data/data2 to data2
Fetching /sftpuser1/data/data3 to data3
sftp> lls
data2 data3
sftp>
|
7. Create and Delete Directories (mkdir, rmdir)
Use mkdir and rmdir:
1
2
3
4
5
6
7
| sftp>
sftp> ls
sftp> mkdir data
sftp> ls
data
sftp> rmdir data
sftp>
|
8. Remove Files (rm)
Use rm to remove remote files:
1
2
3
4
| sftp> rm data*
Removing /sftpuser1/data/data2
Removing /sftpuser1/data/data3
sftp>
|
9. Rename Files (rename)
Use rename:
1
2
3
4
5
6
7
| sftp>
sftp> ls
data3
sftp> rename data3 data_original
sftp> ls
data_original
sftp>
|
10. Check Remote Filesystem Usage (df)
Use df to see remote filesystem usage for current directory/path:
1
2
3
4
5
6
7
| sftp> df
Size Used Avail (root) %Capacity
29540600 5917856 22103188 23622744 20%
sftp> df -h
Size Used Avail (root) %Capacity
28.2GB 5.6GB 21.1GB 22.5GB 20%
|
The output is for the remote server filesystem, not your local machine.
11. Get Help (help or ?)
To list supported SFTP commands:
Example output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
| sftp> ?
Available commands:
bye Quit sftp
cd path Change remote directory to 'path'
chgrp [-h] grp path Change group of file 'path' to 'grp'
chmod [-h] mode path Change permissions of file 'path' to 'mode'
chown [-h] own path Change owner of file 'path' to 'own'
df [-hi] [path] Display statistics for current directory or
filesystem containing 'path'
exit Quit sftp
get [-afpR] remote [local] Download file
help Display this help text
lcd path Change local directory to 'path'
lls [ls-options [path]] Display local directory listing
lmkdir path Create local directory
ln [-s] oldpath newpath Link remote file (-s for symlink)
lpwd Print local working directory
ls [-1afhlnrSt] [path] Display remote directory listing
lumask umask Set local umask to 'umask'
mkdir path Create remote directory
progress Toggle display of progress meter
put [-afpR] local [remote] Upload file
pwd Display remote working directory
quit Quit sftp
reget [-fpR] remote [local] Resume download file
rename oldpath newpath Rename remote file
reput [-fpR] local [remote] Resume upload file
rm path Delete remote file
rmdir path Remove remote directory
symlink oldpath newpath Symlink remote file
version Show SFTP version
!command Execute 'command' in local shell
! Escape to local shell
? Synonym for help
|
For detailed options:
Bonus: Useful SFTP Options
Use SSH private key authentication
1
| sftp -i ~/.ssh/id_ed25519 sftpuser1@192.168.10.10
|
Increase verbosity for debugging
1
| sftp -vvv sftpuser1@192.168.10.10
|
Run in batch mode (automation)
Create a command file:
1
2
3
4
5
6
| cat > sftp-batch.txt <<'EOF'
cd /sftpuser1/data
put report.csv
get latest.log
bye
EOF
|
Run:
1
| sftp -b sftp-batch.txt sftpuser1@192.168.10.10
|
Common SFTP Troubleshooting
Permission denied
- Confirm username/password or key permissions
- Verify target path ownership and write permissions
- Check server-side chroot and SFTP restrictions
Connection timeout or refused
- Verify host/IP and port
- Ensure SSH service is running on the server
- Confirm firewall/security group allows SSH/SFTP
Host key verification failed
- Server host key changed or mismatch in
~/.ssh/known_hosts - Validate server fingerprint, then update known hosts entry safely
Exit the SFTP Session
Exit with bye, exit, or quit:
Summary
You now have a practical workflow for using the Linux SFTP client: connecting securely, navigating directories, transferring files, managing remote content, checking usage, and troubleshooting common errors.
For production environments, prefer SSH key authentication, least-privilege SFTP users, and tightly scoped directory permissions.