Secure File Transfer with SFTP: Remote Server Management
💡 What Will You Learn in This Guide?
This guide teaches you how to securely connect to remote servers using the SFTP (Secure File Transfer Protocol) command line tool.
By establishing an encrypted connection via SSH, you will see the step-by-step process of downloading (get), uploading (put), changing permissions (chmod) and debugging.
🧠 What is SFTP?
SFTP is a secure file transfer protocol built on the SSH protocol.
It works like FTP, but the data is fully encrypted.
In this way, it offers a safe, modern and automation-friendly solution.
Advantages:
- 🔒 End-to-end encryption thanks to SSH infrastructure
- 💻 Can be used from command line or graphical interfaces
- 🧩 File permissions, ownership and directory management supported
🌐 1. Establishing an SFTP Connection
🔹 Basic Link
sftp kullanici@sunucu_adresi
If you can connect via SSH, SFTP is also ready.
🔹 Private Port Usage
sftp -oPort=2222 kullanici@sunucu_adresi
If SSH is running on a different port on your server, connect with this command.
🔹 Help Commands
help
# veya
?
Lists all available SFTP commands.
📂 2. Navigating Directories
| Command | Description |
|---|---|
pwd | Shows the current directory on the remote server. |
ls | Lists the contents of the remote directory. |
cd uzak_dizin | Changes location in the remote directory. |
lpwd | Shows the current directory on the local system. |
lls | Lists the files in the local directory. |
lcd yerel_dizin | Changes directory on the local system. |
Example:
ls -la
It lists all files and their permissions in the remote directory in detail.
📥 3. Download File (get)
To download a file from a remote server to the local system:
get uzakDosya.txt
Download under different name:
get uzakDosya.txt yerelKopya.txt
Downloading the entire folder recursively:
get -r Yedekler
The -P parameter preserves permission and timestamps.
📤 4. File Upload (put)
To upload files from the local system to the remote server:
put rapor.pdf
To load a folder completely:
put -r proje_klasoru
This method can also be used for automated deployment in CI/CD pipelines (e.g. Jenkins, GitLab CI).
🧱 5. File Permissions and Ownership
Changing file permissions:
chmod 755 betik.sh
Changing the file owner:
chown 1001 dosya.txt
Changing the file group:
chgrp 2002 dosya.txt
To find out UID and GID:
get /etc/passwd
get /etc/group
⚙️ 6. Local Command Execution
To run local terminal commands without logging out of SFTP ! is used.
!ls -lh
Lists the files in the local directory.
Only ! You can switch to the local shell by typing, just type exit to go back.
🚀 7. Debugging and SFTP Server Configuration
🔸 Permission Denied
Cause: The user does not have permission to write to the target directory.
Solution:
sudo chown kullanici:kullanici /hedef/dizin
sudo chmod 755 /hedef/dizin
🔸 Connection Refused / Timeout
Cause: SSH service is not running or the port is closed.
Solution:
sudo systemctl status ssh
sudo ufw allow 22
🔸 Host Key Verification Failed
Cause: The server key has changed.
Solution:
ssh-keygen -R sunucu_ip
🔸 Command Not Found
Cause: SFTP subsystem is disabled.
Solution: The following line in the /etc/ssh/sshd_config file must be open:
Subsystem sftp /usr/lib/openssh/sftp-server
🧠 8. Frequently Asked Questions (FAQ)
1. What is the difference between SFTP and FTP?
FTP sends data openly; SFTP, on the other hand, encrypts over SSH. SFTP is the modern alternative to FTP in terms of security.
2. What is the difference between SFTP and SCP?
SCP: Only copies files.
SFTP: Offers copying + directory management + file permissions + listing.
3. What port does SFTP use?
It uses port 22 by default. However, a custom port can also be specified with sftp -oPort=XXXX.
4. Can I use SFTP without SSH access?
Yes, you can grant SFTP-only access using ChrootDirectory and ForceCommand internal-sftp in sshd_config. This increases security in shared environments.
5. Is it possible to automate SFTP transfers?
Absolutely! Scheduled or CI/CD-based automation can be done with bash scripts or the paramiko library in Python.
🌟 Result
SFTP is the most modern and reliable way to transfer files securely with remote servers. Since it works over the SSH protocol, it provides both data privacy and ease of management.
Now you too can: ✅ Establish a secure connection, ✅ Transfer files, ✅ Easily resolve errors.
💼 Take your file transfer skills to professional level by applying these steps on GenixNode Servers now!

