SSH (Secure Shell) provides encrypted access to remote systems and is widely used for administration, backups, and file exchange across networks. Secure file copying avoids exposing data or credentials in transit, which is critical when moving configuration files, application builds, or database exports between environments.

SSH supports several file transfer mechanisms over the same secure transport, including scp for one-shot copies, sftp for interactive transfers, rsync for efficient synchronization, and sshfs for mounting remote filesystems. Each approach uses the same underlying authentication and encryption but offers different workflows for moving data.

Reliable transfers depend on working SSH connectivity, correct permissions on both ends, and sufficient bandwidth for the data volume being moved. The examples use typical /home-based paths, a local account and a remote account as shown in the diagram, and a remote host reachable over standard SSH, with all commands run from a terminal on the local system; the same patterns apply to other directories and hosts with adjusted paths and usernames.

Steps to copy files remotely using SSH:

Ensure working SSH access to the remote server and sufficient permissions on the involved files and directories to avoid failed transfers or partial copies.

Transfer file using scp

scp (Secure Copy) is a straightforward command-line tool for copying files between local and remote systems over SSH. The syntax resembles the cp command but accepts a user and host prefix, which makes it well-suited to quick, non-interactive transfers.

Because scp does not track which files already exist or are up to date on the destination, it is better suited to occasional copies than to large, repetitive synchronizations. For small numbers of files, configuration pushes, or ad‑hoc downloads, it provides a simple and dependable option.

  1. Confirm SSH access to the remote server using the account intended for file transfers.
    $ ssh remoteuser@remoteserver "echo OK"
    OK
  2. Copy a single file from the local system to the remote host using scp.
    $ scp /home/localuser/localfolder/subdir1/file1.txt remoteuser@remoteserver:/home/remoteuser/remotefolder/subdir1/
    remoteuser@remoteserver's password:
    file1.txt                                      100%  123KB  3.2MB/s   00:00
  3. Copy a single file from the remote host to the local system using scp.
    $ scp remoteuser@remoteserver:/home/remoteuser/remotefolder/subdir1/file1.txt /home/localuser/localfolder/subdir1/
    remoteuser@remoteserver's password:
    file1.txt                                      100%  123KB  3.1MB/s   00:00
  4. Copy multiple files from the local system into the same remote directory with one scp command.
    $ scp /home/localuser/localfolder/subdir1/file1.txt /home/localuser/localfolder/subdir2/file2.txt remoteuser@remoteserver:/home/remoteuser/remotefolder/
    remoteuser@remoteserver's password:
    file1.txt                                      100%  123KB  3.0MB/s   00:00
    file2.txt                                      100%  256KB  3.5MB/s   00:00
  5. Recursively transfer an entire local directory tree to the remote host using the -r option in scp.
    $ scp -r /home/localuser/localfolder/ remoteuser@remoteserver:/home/remoteuser/remotefolder/
    remoteuser@remoteserver's password:
    file1.txt                                      100%  123KB  3.4MB/s   00:00
    file2.txt                                      100%  256KB  3.6MB/s   00:00
    ##### snipped #####
  6. Verify that the expected files exist on the remote side after the transfer.
    $ ssh remoteuser@remoteserver "ls -R /home/remoteuser/remotefolder"
    /home/remoteuser/remotefolder:
    file1.txt  file2.txt  subdir1  subdir2
    
    /home/remoteuser/remotefolder/subdir1:
    file1.txt
    
    /home/remoteuser/remotefolder/subdir2:
    file2.txt

GUI programs such as WinSCP can transfer files between local and remote hosts using scp or sftp while providing drag‑and‑drop file management.

Transfer file using sftp

sftp (SSH File Transfer Protocol) provides an interactive shell over SSH for navigating directories and transferring files. The prompt accepts commands similar to traditional file managers, which makes it convenient for exploring remote paths and moving several files in a single session.

The interactive nature of sftp also supports batch uploads or downloads and can resume interrupted transfers in many cases, making it practical when the exact filenames or locations are not fully known in advance.

  1. Start an sftp session by connecting to the remote server.
    $ sftp remoteuser@remoteserver
    remoteuser@remoteserver's password:
    Connected to remoteserver.
    sftp>
  2. List and navigate directories on the remote server using commands such as ls and cd at the sftp prompt.
    sftp> ls /home/remoteuser/remotefolder/
    subdir1  subdir2
    sftp> cd /home/remoteuser/remotefolder/subdir1
    sftp> pwd
    Remote working directory: /home/remoteuser/remotefolder/subdir1
  3. Download a file from the remote server to a local directory with the get command.
    sftp> get /home/remoteuser/remotefolder/subdir1/file1.txt /home/localuser/localfolder/subdir1/
    Fetching /home/remoteuser/remotefolder/subdir1/file1.txt to /home/localuser/localfolder/subdir1/file1.txt
    /home/localuser/localfolder/subdir1/file1.txt       100%  123KB  3.2MB/s   00:00
  4. Upload a local file to the remote server with the put command.
    sftp> put /home/localuser/localfolder/subdir1/file1.txt /home/remoteuser/remotefolder/subdir1/
    Uploading /home/localuser/localfolder/subdir1/file1.txt to /home/remoteuser/remotefolder/subdir1/file1.txt
    /home/remoteuser/remotefolder/subdir1/file1.txt     100%  123KB  3.1MB/s   00:00
  5. End the sftp session when transfers are complete.
    sftp> bye
  6. Confirm that the transferred file exists on the local system after a download or on the remote system after an upload.
    $ ls /home/localuser/localfolder/subdir1/
    file1.txt

Transfer file using rsync

rsync synchronizes files and directories between local and remote systems while sending only the differences between source and destination. This behavior greatly reduces traffic for repeated transfers, which is useful for backups, mirrors, and deployment trees.

When used with a destination in the form remoteuser@remoteserver:/path, rsync runs over SSH and preserves permissions, ownership, timestamps, and symbolic links when requested. Using the -e option explicitly selects ssh as the remote shell, while double‑colon syntax (for example, remoteserver::module/path) targets an rsyncd daemon instead.

  1. Verify that network access and SSH authentication work between the local host and the remote server.
    $ ssh remoteuser@remoteserver "hostname"
    remoteserver
  2. Synchronize a local directory to a remote directory over SSH, deleting files on the destination that no longer exist at the source.
    $ rsync -av --delete -e ssh /home/localuser/localfolder/ remoteuser@remoteserver:/home/remoteuser/remotefolder/
    sending incremental file list
    ./
    file1.txt
    file2.txt
    
    sent 1,234 bytes  received 56 bytes  2,580.00 bytes/sec
    total size is 379,000  speedup is 292.00
  3. Mirror a remote directory to a local directory using the same flags in reverse.
    $ rsync -av --delete -e ssh remoteuser@remoteserver:/home/remoteuser/remotefolder/ /home/localuser/localfolder/
    sending incremental file list
    ./
    file1.txt
    file2.txt
    
    sent 1,210 bytes  received 78 bytes  2,576.00 bytes/sec
    total size is 379,000  speedup is 285.00
  4. Transfer only files that are new or modified on the source by using the --update option so existing newer files on the destination remain unchanged.
    $ rsync -av --update -e ssh /home/localuser/localfolder/ remoteuser@remoteserver:/home/remoteuser/remotefolder/
    sending incremental file list
    
    sent 400 bytes  received 40 bytes  880.00 bytes/sec
    total size is 379,000  speedup is 860.00
  5. Exclude specific patterns such as log files from synchronization with the --exclude option.
    $ rsync -av --exclude '*.log' -e ssh /home/localuser/localfolder/ remoteuser@remoteserver:/home/remoteuser/remotefolder/
    sending incremental file list
    ./
    file1.txt
    file2.txt
    
    sent 900 bytes  received 60 bytes  1,920.00 bytes/sec
    total size is 378,000  speedup is 360.00
  6. Verify the result by listing key paths on the destination and checking that only the expected files are present.
    $ ssh remoteuser@remoteserver "ls -R /home/remoteuser/remotefolder"
    /home/remoteuser/remotefolder:
    file1.txt  file2.txt  subdir1  subdir2

Mount remote filesystem locally

sshfs mounts a remote directory over SSH so that remote files appear as part of the local filesystem. This approach allows normal tools such as cp, text editors, or backup programs to operate on remote data without special transfer commands.

Mounting a remote filesystem is particularly useful for working on many small files or for tools that are not SSH‑aware but can operate on local paths.

Discuss the article:

Comment anonymously. Login not required.