Linux Utility - Scp (secure copy, remote file copy) command
Table of Contents
About
File Transfer - SCP (Secure Copy) in Linux.
Articles Related
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
How to
Transfer files from one Linux host to an other
A directory
Example to copy recursively the local directory to a remote with sshpass to pass the password
sshpass -f "/my/file/witth/pwd" \
scp -pr . [email protected]:/Target/Directory
where:
- -p Preserves modification times, access times, and modes from the original file.
- r Recursively copy entire directories.
You may be able to pass the password with the PWD environment variable.
scp -pr . [email protected]:$PWD
One file
sshpass -p "mypassword" \
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
Support
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" [email protected]:"/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" [email protected]:"\"/tmp/Path With Space\""