Close Menu
IOupdate | IT News and SelfhostingIOupdate | IT News and Selfhosting
  • Home
  • News
  • Blog
  • Selfhosting
  • AI
  • Linux
  • Cyber Security
  • Gadgets
  • Gaming

Subscribe to Updates

Get the latest creative news from ioupdate about Tech trends, Gaming and Gadgets.

[contact-form-7 id="dd1f6aa" title="Newsletter"]
What's Hot

Testing Proxmox 9 Snapshots as Volume Chains on iSCSI (Tech Preview)

August 13, 2025

Z-Wave reborn – Home Assistant Connect ZWA-2

August 13, 2025

Awesome List Updates on May 17, 2025

August 13, 2025
Facebook X (Twitter) Instagram
Facebook Mastodon Bluesky Reddit
IOupdate | IT News and SelfhostingIOupdate | IT News and Selfhosting
  • Home
  • News
  • Blog
  • Selfhosting
  • AI
  • Linux
  • Cyber Security
  • Gadgets
  • Gaming
IOupdate | IT News and SelfhostingIOupdate | IT News and Selfhosting
Home»Linux»10 sFTP Commands to Move Files Between Linux Systems
Linux

10 sFTP Commands to Move Files Between Linux Systems

MarkBy MarkAugust 10, 2025No Comments6 Mins Read
10 sFTP Commands to Move Files Between Linux Systems


Introduction

Ditch the vulnerabilities of FTP and level up your server management skills. This guide explores the sftp command, an essential tool for secure file transfer on any Linux system. Learn how SFTP leverages the power of SSH to protect your data during transmission. We’ll walk you through practical examples, from basic connections and file transfers to advanced techniques like recursive directory uploads and passwordless authentication, helping you master a fundamental aspect of Linux administration.

What is SFTP and Why Is It More Secure Than FTP?

File Transfer Protocol (FTP) was once the standard for moving files remotely. However, its critical flaw is that it transmits all data, including usernames and passwords, in unencrypted clear text. This makes it highly insecure, as anyone monitoring network traffic can easily intercept your credentials and data. Due to this vulnerability, FTP should only be used on networks you completely trust.

SFTP (Secure File Transfer Protocol) solves this problem. It is not a simple upgrade to FTP but a completely different protocol built on top of the Secure Shell (SSH) protocol. By default, it operates over the standard SSH port 22, creating a secure, encrypted channel for all commands and data transfers. This ensures that your credentials and files are protected from eavesdropping, making it the modern standard for any Linux file transfer.

Most Linux distributions come with the sftp client pre-installed. You can verify its presence by running:

which sftp

If the command returns a path like /usr/bin/sftp, you are ready to proceed.

Security Warning: Please don’t expose your SSH port to the public internet without proper security measures. It is best practice to use a firewall to allow access only from specific, trusted IP addresses.

Connecting and Navigating with the SFTP Command

Mastering the initial connection and navigation is the first step to using SFTP effectively.

H3: Establishing a Secure Connection

To start an SFTP session, you use the same credentials and protocol as SSH. Simply provide your username and the remote server’s hostname or IP address:

sftp [email protected]

If the remote SSH server is running on a non-standard port (e.g., 2222), you can specify it with the -oPort option:

sftp -oPort=2222 [email protected]

Once authenticated, your command prompt will change to sftp>, indicating you are in an active SFTP session. You can type help or ? to see a list of available commands.

H3: Checking Your Current Directory (Remote and Local)

Knowing your location on both the local and remote systems is crucial. SFTP provides two simple commands for this:

  • pwd: Shows your present working directory on the remote server.
  • lpwd: Shows your present working directory on your local machine.

sftp> pwd
Remote working directory: /tecmint/
sftp> lpwd
Local working directory: /home/user/documents

H3: Listing Files on Remote and Local Machines

To see the contents of a directory, you use commands similar to pwd and lpwd:

  • ls: Lists files and directories in the current remote directory.
  • lls: Lists files and directories in the current local directory.

For a more detailed view, you can use the -l flag with both commands to show permissions, owner, size, and modification date.

sftp> ls -l
sftp> lls -l

Mastering Secure File Transfer with SFTP

The core function of SFTP is, of course, transferring files. Here’s how to upload and download single files, multiple files, and even entire directories.

H3: Uploading Files to a Remote Server

To upload a single file from your local machine to the remote server, use the put command. This will copy the specified file from your current local directory to the current remote directory.

sftp> put local.profile

To upload multiple files at once, such as all files ending with .log, use the mput command with a wildcard:

sftp> mput *.log

H3: Downloading Files from a Remote Server

To download a single file from the remote server to your local machine, use the get command.

sftp> get SettlementReport_1-10th.xls

For downloading multiple files that match a pattern, use the mget command. This example downloads all spreadsheet files:

sftp> mget *.xls

H3: Renaming Files While Downloading

If you need to save a downloaded file with a different name on your local machine, simply specify the new filename as a second argument to the get command.

sftp> get SettlementReport_1-10th.xls Report_Jan.xls

This command downloads SettlementReport_1-10th.xls from the server and saves it locally as Report_Jan.xls.

Advanced SFTP Command Techniques and Management

Go beyond simple transfers with these commands for directory management, automation, and session control.

H3: Switching, Creating, and Removing Directories

Managing directories is straightforward within an SFTP session:

  • Switch Directories: Use cd for the remote server and lcd for your local machine.
  • sftp> cd /var/www/html
    sftp> lcd /home/user/new-project

  • Create Directories: Use mkdir for the remote server and lmkdir for your local machine.
  • sftp> mkdir backups
    sftp> lmkdir downloads

  • Remove Files and Directories: Use rm to delete a remote file and rmdir to delete an empty remote directory.
  • sftp> rm old_backup.tar.gz
    sftp> rmdir temp_folder

Note: The rmdir command will fail if the directory is not empty. You must remove its contents first.

H3: Automate Logins with SSH Key Authentication

To perform a secure file transfer without repeatedly typing your password, use SSH key-based authentication. First, generate a key pair on your local machine if you don’t have one:

ssh-keygen -t rsa -b 4096

Next, copy your public key to the remote server using the ssh-copy-id utility:

ssh-copy-id [email protected]

Once the key is copied, you can connect via SFTP without a password prompt, which is ideal for scripting and automation.

sftp [email protected]

H3: Exiting the Session and Using the Local Shell

To close the SFTP session, simply type bye or exit.

If you need to run a command on your local machine without ending your SFTP session, use the ! command. This will temporarily drop you into your local shell.

sftp> !

After running your local commands, type exit to return to your active SFTP prompt.

sftp> bye

FAQ

Question 1: What is the main difference between FTP and SFTP?

Answer 1: The primary difference is security. FTP transmits data and credentials in unencrypted plain text, making it vulnerable to interception. SFTP (Secure File Transfer Protocol) runs over an SSH connection, encrypting all data, including login credentials, which protects your information during transit. SFTP is the modern, secure standard for transferring files.

Question 2: Can I transfer an entire directory with a single SFTP command?

Answer 2: Yes. While the basic mput and mget commands don’t handle subdirectories, you can transfer entire directories recursively using the -r (recursive) flag. This is a powerful feature for moving entire project folders or backups. For example, to download a remote directory named ‘project-files’ to your local machine, you would use: sftp> get -r project-files.

Question 3: How can I automate a series of SFTP commands?

Answer 3: You can automate SFTP transfers by using a batch file. Create a text file (e.g., `sftp_script.txt`) containing one sftp command per line (e.g., `cd /remote/path`, `put localfile.zip`, `bye`). Then, execute it using the `-b` (batch file) option: `sftp -b sftp_script.txt [email protected]`. This is especially powerful when combined with SSH key authentication for fully automated, passwordless workflows.



Read the original article

0 Like this
Commands files Linux Move SFTP systems
Share. Facebook LinkedIn Email Bluesky Reddit WhatsApp Threads Copy Link Twitter
Previous ArticlePolicy compliance & the cybersecurity silver bullet
Next Article RFK Jr. wants a wearable on every American — that future’s not as healthy as he thinks

Related Posts

Linux

AWS Fiasco, AUR Poisoned Again, Ubuntu Manual, Firefox New Tab Customization and More Linux Stuff

August 8, 2025
Linux

Arch Linux Installer Gets U2F Authentication and Bluetooth Support

August 7, 2025
Linux

Setting up Next DNS – Pixelated Dwarf

August 7, 2025
Add A Comment
Leave A Reply Cancel Reply

Top Posts

AI Developers Look Beyond Chain-of-Thought Prompting

May 9, 202515 Views

6 Reasons Not to Use US Internet Services Under Trump Anymore – An EU Perspective

April 21, 202512 Views

Andy’s Tech

April 19, 20259 Views
Stay In Touch
  • Facebook
  • Mastodon
  • Bluesky
  • Reddit

Subscribe to Updates

Get the latest creative news from ioupdate about Tech trends, Gaming and Gadgets.

About Us

Welcome to IOupdate — your trusted source for the latest in IT news and self-hosting insights. At IOupdate, we are a dedicated team of technology enthusiasts committed to delivering timely and relevant information in the ever-evolving world of information technology. Our passion lies in exploring the realms of self-hosting, open-source solutions, and the broader IT landscape.

Most Popular

AI Developers Look Beyond Chain-of-Thought Prompting

May 9, 202515 Views

6 Reasons Not to Use US Internet Services Under Trump Anymore – An EU Perspective

April 21, 202512 Views

Subscribe to Updates

Facebook Mastodon Bluesky Reddit
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions
© 2025 ioupdate. All Right Reserved.

Type above and press Enter to search. Press Esc to cancel.