Skip to main content

Secure file transfer between Linux and Linux servers

SFTP (Secure File Transfer Protocol) is a secure way to transfer files between your Linux machine and a Linux server. This article explains how to use the sftp command in the Linux terminal to copy files securely.

Step 1: Ensure SSH is enabled on your Linux server

Make sure the SSH service is installed and running on your Linux server. Use the following command:

Step 2: Use the sftp command to transfer files

Connect to the server

To start an SFTP session, use the following command:
  • Replace username with your Linux server username.
  • Replace hostname_or_ip with your server’s IP address or domain name.

Transfer files using SFTP commands

Once connected, you can use the following commands to transfer files: Run these commands at the sftp> prompt after connecting: Replace the example paths with existing directories you can access. Transfers can overwrite an existing destination file with the same name. For a custom SSH port, connect from your local terminal with sftp -P 2222 username@hostname_or_ip. The port option is uppercase -P. See the OpenSSH SFTP manual.

Example commands

Upload example

Download example


Last modified on September 30, 2026