SFTP (Secure File Transfer Protocol) Command Reference Guide
Comprehensive whitepaper for secure file transfer with SFTP, remote server management and automation commands.
Contents
What is SFTP and How to Use it? It is a standard tool that allows you to transfer. This guide covers basic commands used in file management, transfer operations and automation scenarios.1. Connection and Authentication
To connect to a remote server, simply use the sftp command in your terminal. If a port other than the default SSH port (22) is used, it must be specified with the -P parameter.
- Standard connection:
sftp user@hostname - Connection via special port:
sftp -P 2222 user@hostname - Connection with SSH key:
sftp -i ~/.ssh/id_ed25519 user@hostname
Tip: You can use the
quitorbyecommand to end the connection.
2. File Navigation and Directory Management
You can switch between local and remote directories during an SFTP session. The prefix 'l' (local) refers to operations on the local machine.
- Listing the remote directory:
ls - Listing the local directory:
lls - Remote directory modification:
cd /remote/path - Local directory modification:
lcd /local/path
3. File Transfer (Upload/Download)
get and put commands are used to pull files from the server or send them to the server.
- File download:
get file.txt - Directory download (recursive):
get -r remote_directory - File upload:
put file.txt - Resuming the interrupted transfer:
reget file.iso
4. Remote File Management and Permissions
You can directly manage the ownership and permissions of files on the server.
- Directory creation:
mkdir directory_name - File deletion:
rm file.txt - Permission change:
chmod 644 file.txt - Ownership change:
chown 1000 files.txt
5. Automation and Scripting
To automate SFTP, you can run a script with the -b (batch) parameter.
sftp -b commands.txt user@hostnameWarning: It is critical that you use an SSH key in automated tasks to avoid being stuck on the password request screen.
SFTP, It is one of the cornerstones of modern systems administration, along with tools such as SCP and Rsync. For more complex synchronization needs, you may consider using rsync.