Linux Utility - Scp (secure copy, remote file copy) command

> Procedural Languages > Bash Shell and (Unix|Linux) Utilities (XCU)

1 - About

Advertising

3 - Syntax

 scp 
    [-1246BCpqrv] 
    [-c cipher] 
    [-F ssh_config] 
    [-i identity_file] 
    [-l limit] 
    [-o ssh_option] 
    [-P port] 
    [-S program]
    [[[email protected]]host1:]SourceFile1 [...] [[[email protected]]host2:]TargetFile2

4 - How to

4.1 - Transfer files from one Linux host to an other

4.1.1 - A directory

scp -pr . [email protected]:/Target/Directory

where:

  • -p Preserves modification times, access times, and modes from the original file.
  • r Recursively copy entire directories.

Generally, you use it with the PWD environment variable.

scp -pr . [email protected]:$PWD

4.1.2 - One file

scp -p myFile [email protected]:/myPath/myFile

where:

  • -p Preserves modification times, access times, and modes from the original file.
The authenticity of host 'MyDestinationHost(192.168.0.1)' can't be established.
RSA key fingerprint is 45:b8:dc:fd:22:da:73:eb:db:e3:fb:89:7e:c8:0a:6e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'MyDestinationHost,192.168.0.1' (RSA) to the list of known hosts.
[email protected]'s password:
SAF_OR_10M_T.dmp                              100% 3555MB   7.0MB/s   08:30
Advertising

5 - Support

5.1 - scp: ambiguous target caused by space in path

The below scp command will get you a scp: ambiguous target error message because of the spaces in the last argument.

scp -p "/tmp/Path With Space" user@host:"/tmp/Path With Space"

To resolve this issue, just quote the whole path of the last argument without forgetting the escape character.

Full example;

scp -p "/tmp/Path With Space" user@host:"\"/tmp/Path With Space\""
lang/bash/scp.txt · Last modified: 2017/08/08 12:57 by gerardnico