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
- How to Set Up an SFTP Server on Debian
- Download Files from SFTP Server Using Python
- List, Upload, and Download Files from an SFTP Server Using Golang
- How to Set Up an SFTP Server on OpenSUSE
- How to Install and Set Up SFTP Server in Ubuntu
- How to Set Up an SFTP Server on CentOS/RHEL
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:
| |
Example output:
| |
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:
| |
2. Check SFTP Version
Inside the SFTP prompt:
| |
3. Show Remote Working Directory (pwd)
Use pwd to print your current remote directory:
| |
4. Show Local Working Directory (lpwd)
Use lpwd to print your current local directory:
| |
Change remote directories with cd:
| |
You can also change local directories with lcd:
| |
5. Upload Files to SFTP Server (put, mput)
Upload a file using one-line mode
| |
Example:
| |
Upload from interactive SFTP shell
| |
Upload multiple files with mput:
| |
6. Download Files from SFTP Server (get, mget)
Download a file in one command
| |
Example:
| |
Download from interactive session
| |
Download multiple files with mget:
| |
7. Create and Delete Directories (mkdir, rmdir)
Use mkdir and rmdir:
| |
8. Remove Files (rm)
Use rm to remove remote files:
| |
9. Rename Files (rename)
Use rename:
| |
10. Check Remote Filesystem Usage (df)
Use df to see remote filesystem usage for current directory/path:
| |
The output is for the remote server filesystem, not your local machine.
11. Get Help (help or ?)
To list supported SFTP commands:
| |
Example output:
| |
For detailed options:
| |
Bonus: Useful SFTP Options
Use SSH private key authentication
| |
Increase verbosity for debugging
| |
Run in batch mode (automation)
Create a command file:
| |
Run:
| |
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.