Skip to main content

SFTP: Secure File Transfer with SSH

Introduction to SFTP

SFTP stands for "Secure File Transfer Protocol". Unlike traditional FTP, which transmits login credentials and data without encryption, SFTP provides file transfer capabilities over a secure SSH (Secure Shell) connection. This ensures that the data, including credentials, is encrypted and shielded from potential eavesdroppers.

Why Use SFTP Over Traditional FTP?

  • Security: Traditional FTP doesn't encrypt its data, making it susceptible to eavesdropping. SFTP, on the other hand, utilizes SSH's encryption capabilities, ensuring the data remains confidential during transit.

  • Integrity: SFTP includes mechanisms to ensure that data hasn't been altered during transmission, adding an extra layer of trustworthiness.

  • Authentication: SFTP can use SSH keys for authentication, providing a more secure and convenient method than simple password authentication.

Transferring Files with SFTP

To use SFTP, you'll need to establish an SSH connection. Once that's done, you can use SFTP commands within that secure shell to move files between the host and the client.

Connecting to a Remote Server with SFTP

To start an SFTP session, use the sftp command followed by the username and hostname (or IP address) of the remote server:

sftp username@hostname

For example:


After running the command, you'll be prompted to enter the user's password. Once authenticated, you'll enter the SFTP environment.

Basic SFTP Commands

Here are some fundamental SFTP commands you can use:

  • pwd: Print the current directory on the remote system.

  • lpwd: Print the current directory on the local system.

  • ls: List files in the current directory on the remote system.

  • lls: List files in the current directory on the local system.

  • cd <directory>: Change the directory on the remote system.

  • lcd <directory>: Change the directory on the local system.

  • get <filename>: Download a file from the remote system to the local system.

  • put <filename>: Upload a file from the local system to the remote system.

Transferring Files with SFTP

  1. Uploading a File

To upload a file from your local machine to the remote server:

put local-file.txt

This will transfer local-file.txt from your machine to the remote server's current directory.

  1. Downloading a File

To download a file from the remote server to your local machine:

get remote-file.txt

This will fetch remote-file.txt from the server and store it in your current local directory.

Ending the SFTP Session

When you're done transferring files, you can exit the SFTP session with:


or simply:



SFTP is a secure and reliable method for transferring files between a client and a server. By leveraging the security features of SSH, SFTP ensures that your data remains protected during transit. Whether you're uploading or downloading files, using SFTP commands can help you achieve your objectives efficiently and securely.

What Can You Do Next 🙏😊

If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for software developers.

YouTube @cloudaffle