Thursday, 12 April 2012

SCP Command Examples

SCP stands for 'secure copy' its a good way of sending files over a network securely. To use this command you need to have SSH installed.
(for those of you who don't know SSH (secure shell) is a protocol for securely connecting to a remote machine). A good example of SCP is shown below:
scp somefile someUser@ipaddress 

Its quite simple to use really, you'll find it useful if you use SSH a lot as I do.
Below I have listed a few fun/interesting scp commands. Enjoy :D

Edit a file on a remote host using VIM
vim scp://auser@ahost//path/to/somefile
I find this useful when you don't want to take the file, only edit it.

Compare a remote file with a local file
vimdiff afile.txt scp://[user@]host/<anotherfile.txt>
Again this is just as useful as the one above. you can also use this for coloured difference between to remote hosts.
vimdiff scp://user@server//path/to/file scp://user@server//path/to/file

SCP with Compression
scp -C /path/to/backup.sql
-C - Compression
useful for all the DB heads out there.

SCP from one machine to another while logged into a third
scp user@hostb:file user@hostc:
scp a file from host b to host c while logged into host a. kinda fun I think

SCP a file to the same location on the remote machine
scp filename root@remote:`pwd`
this is very useful, I mean you could just write the path...but the pwd is there for a reason!

No comments:

Post a Comment