Monday, July 4, 2011

SCP or how to securely transfer files

scp is a useful command. It works on top of ssh.
To transfer file from local to remote:
scp sourcefile user@remoteserver:/path_target/

To transfer from remote to local:
scp user@remoteserver:/path_source/sourcefile /path_target/
Note: if the target is current directory then '.' can be used as in scp user@remoteserver:/path_source/sourcefile .
if the target is the parent directory current directory then '..' can be used as in scp user@remoteserver:/path_source/sourcefile ..

To transfer files from one remote to another remote:
scp user@remoteserver1:/path_source/sourcefile user@remoteserver2:/path_target/
Note: the server must be able to reach each other because files will be transferred directly between them.

To transfer using some specified port:
scp -P port_number user@remoteserver:/path_source/sourcefile .

To transfer all files in a directory:
scp user@remote:/source_path/* .

To transfer a directory recursively:
scp -r user@remote:/source_path/ .

To limit bandwidth used:
scp -l bandwidth user@remoteserver:/path_source/sourcefile .

To view file in remote machine:
vi scp://user@remote/source_path/remotefile

To compare files:
vimdiff scp://user@remote/source_path/remotefile localfile

No comments:

Post a Comment