Copying files over SSH moves configuration files, scripts, archives, or release artifacts to another system without opening a separate file-transfer service. The same encrypted connection that protects an interactive SSH login also protects the file data and the authentication process during the transfer.

On current OpenSSH clients, scp remains the simplest command for this job. It uses the same username, host key checks, private keys, and authentication flow as a normal ssh user@host.example.net session, and current releases transfer the data over the SFTP subsystem even though the command name stays scp.

The remote SSH service must already be reachable, the destination path must already exist, and the remote account must have permission to write there before the upload begins. The examples below assume a current Linux client, a remote account named user, and a destination under /home/user/remotefolder; add -P for a non-default SSH port, add -i for a specific private key file, and reserve -O for older servers that still need the legacy SCP protocol instead of the default SFTP transfer mode.

Steps to copy files with scp over SSH:

  1. Create the remote destination directories before copying.
    $ ssh user@host.example.net 'mkdir -p /home/user/remotefolder/subdir1 /home/user/remotefolder/subdir2'

    Current scp uploads use SFTP by default, so missing parent directories cause the transfer to fail instead of being created automatically.

  2. Copy one local file into the remote target directory with scp.
    $ scp /home/user/localfolder/subdir1/file1.txt user@host.example.net:/home/user/remotefolder/subdir1/
    file1.txt                                     100%

    Add -P for a non-default SSH port or -i for a private key file that is not loaded automatically.

  3. Copy multiple local files into the same remote directory.
    $ scp /home/user/localfolder/subdir1/file1.txt /home/user/localfolder/subdir2/file2.txt user@host.example.net:/home/user/remotefolder/
    file1.txt                                     100%
    file2.txt                                     100%

    All source paths come before the final remote destination on the scp command line.

  4. Recursively copy a whole directory tree with scp -r.
    $ scp -r /home/user/localfolder user@host.example.net:/home/user/remotefolder/
    file1.txt                                     100%
    file2.txt                                     100%

    This creates /home/user/remotefolder/localfolder on the remote host and copies the source tree into it.

    scp -r follows symbolic links it encounters during the traversal, so linked directories can copy more data than expected.

  5. Verify that the expected files arrived under the remote path.
    $ ssh user@host.example.net 'ls -lR /home/user/remotefolder'
    /home/user/remotefolder:
    total 20
    -rw-r--r-- 1 user user   10 Apr 14 04:48 file1.txt
    -rw-r--r-- 1 user user   11 Apr 14 04:48 file2.txt
    drwxr-xr-x 4 user user 4096 Apr 14 04:48 localfolder
    drwxr-xr-x 2 user user 4096 Apr 14 04:48 subdir1
    drwxr-xr-x 2 user user 4096 Apr 14 04:48 subdir2
    
    /home/user/remotefolder/localfolder:
    total 8
    drwxr-xr-x 2 user user 4096 Apr 14 04:48 subdir1
    drwxr-xr-x 2 user user 4096 Apr 14 04:48 subdir2
    
    /home/user/remotefolder/localfolder/subdir1:
    total 4
    -rw-r--r-- 1 user user 10 Apr 14 04:48 file1.txt
    
    /home/user/remotefolder/localfolder/subdir2:
    total 4
    -rw-r--r-- 1 user user 11 Apr 14 04:48 file2.txt
    
    /home/user/remotefolder/subdir1:
    total 4
    -rw-r--r-- 1 user user 10 Apr 14 04:48 file1.txt
    
    /home/user/remotefolder/subdir2:
    total 0

    The remote listing confirms that the single-file upload, multi-file upload, and recursive copy all landed under the intended destination tree.