Skip to main content
In this lesson we’ll cover how to securely transfer files and directories between systems using SFTP (Secure File Transfer Protocol). SFTP runs over SSH and provides an encrypted, authenticated channel for transferring files—making it a safer alternative than plain FTP. Compared with scp, SFTP is more interactive and feature-rich, offering directory listings, resume support, and both remote and local command variants.
SFTP (part of the SSH suite) encrypts both authentication and data, protecting credentials and file contents while in transit.

Starting an SFTP session

To begin an interactive SFTP session from a client machine:
After connecting you will see the sftp> prompt. Type help or ? to list available commands. Commands prefixed with l operate on the local machine (for example, lls, lcd, lpwd), while commands without the l operate on the remote host (for example, ls, cd, pwd).

Quick reference: common SFTP commands

Interactive help and local vs remote commands

Example short help output inside an SFTP session:
Local vs remote listing example:

Demo: preparing files locally and remotely

Create a local demo directory and two files on the control machine:
On the remote host (node1) create a target directory and two remote files:

Interactive SFTP session: navigate, upload, and download

Connect from the control node to the remote node using SFTP:
A sample interactive session showing local/remote navigation, uploads, and downloads:
Upload local files file1 and file2 to the remote incoming directory:
Download remote files incoming1 and incoming2 to the local directory:
Exit the session:

Non-interactive, one-liner transfers

SFTP also supports non-interactive one-liners to fetch or push a single file without entering the interactive prompt. Example: download a remote file directly into your local home directory:
This command connects, downloads the specified remote file to ~, and exits immediately.
To transfer entire directories, use the -r option with put or get (for example, put -r my_photos/ or get -r /remote/path/).

Recap and next steps

  • SFTP is an SSH-based secure file transfer tool that supports interactive and non-interactive workflows.
  • Use put to upload and get to download. Prefix commands with l to operate on the local machine (e.g., lls, lpwd).
  • For directories, use -r to transfer recursively.
  • Use one-liners to script single file transfers, or open an interactive session for multi-step operations.
Further reading and references: This concludes the lesson on securely transferring files with SFTP.

Watch Video

Practice Lab