10 Examples: Copying Files over SSH

SCP (Secure CoPy) – is a remote file copy program, that copies files between hosts on a network.

It uses SSH for data transfer, and uses the same authentication and provides the same security as SSH.

When copying a source file to a target file which already exists, SCP will replace the contents of the target file. If the target file does not yet exist, an empty file with the target file name is created, then filled with the source file contents.

Example 1: Copy the file “file.txt” from a remote host to the local host.

$ scp user@remote.host:file.txt /some/local/directory

Example 2: Copy the file “file.txt” from the local host to a remote host.

$ scp file.txt user@remote.host:/some/remote/directory

Example 3: Copy the directory “dir1” from the local host to a remote host’s directory “dir2”.

$ scp -r dir1 user@remote.host:/some/remote/directory/dir2

Example 4: Copy the file “file.txt” from remote host “remote.host1” to remote host “remote.host2”.

$ scp user@remote.host1:/directory/file.txt user@remote.host2:/some/directory/

Example 5: Copy the files “file1.txt” and “file2.txt” from the local host to your home directory on the remote host.

$ scp file1.txt file2.txt user@remote.host:~

Example 6: Copy the file “file.txt” from the local host to a remote host using port 2222.

$ scp -P 2222 file.txt user@remote.host:/some/remote/directory

Example 7: Copy the file “file.txt” from the local host to a remote host’s home directory. Preserve the modification and access times, as well as the permissions of the source-file in the destination-file.

$ scp -p file.txt user@remote.host:~

Example 8: Copy the file “file.txt” from the local host to a remote host’s home directory. Increase SCP speed by changing the cipher from the default AES-128 to Blowfish.

$ scp -c blowfish file.txt user@remote.host:~

Example 9: Copy the file “file.txt” from the local host to a remote host’s home directory. limit the bandwidth used by SCP command to 100 Kbit/s.

$ scp -l 100 file.txt user@remote.host:~

Example 10: Copy multiple files from the remote host to your current directory on the local host.

$ scp user@remote.host:~/\{file1,file2,file3\} .
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Start a GUI Application on a Remote Computer using SSH

This article describes how to log into the remote computer (server) using SSH and run a GUI...

SSH Login Slow — Removing Delay

Problem: When I’m trying to log into the remote server via SSH, after I enter the UserName, it...

SSHPass: SSH Login With Password – Command Line

A password-based authentication is often a default way to connect to a remote host over SSH. But...

Signing Failed: Agent Refused Operation [SOLVED]

While attempting to connect to some server over SSH, you may get the error as follows:...

SSH Fingerprint: Get Fingerprint of SSH RSA Key

The fingerprint is a unique sequence of letters and numbers used to identify the SSH RSA key. It...