Copying files from one unix box to another with scp
ssh is a very powerful and widely used protocol in all the Unices. If you’ve used the ssh client in your Unix/Linux box, you must have realised how indispensable it is. There is another indispensable tool that uses the ssh protocol – scp (secure copy). scp was meant to be an alternative to unsecure tools like rcp. It has since replaced most such programs. Since scp uses the ssh protocol, the encryption it uses ensures security of your data.
Using scp is simple. It works almost like the regular cp command. The basic syntax is
scp SOURCE DESTINATION
In order to specify the SOURCE or DESTINATION we have a special syntax.
USERNAME@HOST:PATH
Let me give you an example :
$scp anirudh@box:/var/www/html/test.html gingerjoos@linux:~/test_dir/
Copy /var/www/html/test.html in the machine called “box” as user “anirudh” to the box called “linux” as user “gingerjoos” to the path HOMEDIR/test_dir/
That’s it
Simple, right?
To copy the file to our localmachine, we could do this
$scp anirudh@box:/var/www/html/test.html ~/workarea/
This would copy the file test.html in the machine called “box” (as user anirudh) to the localmachine at path HOMEDIR/work_area/
Interchange the source-destination to copy file in your localmachine to the remote machine.
If you want to copy whole directories, use the ‘-r’ flag(recursive copy)
$scp -r ~/workarea/ anirudh@box:~/workdir/
Since scp is tied to the ssh program, the keys you use to set up passwordless login with ssh works for scp as well.
Got questions? Got something to add to this? Post your comments below
Related posts:


We have a software to do scp from windows.
Winscp its open source.
Yup, there are other scp/ssh clients available for windows too. Filezilla and putty come to mind.
[...] Copying files from one unix box to another with scp | Dreams of Thought This will come in handy more than once – Unix/Linux command line – SCP [...]
I have one more point to add.
Do not use scp when your source contains hard/soft links and you want to copy them as it is. Instead of links, scp will copy the actual file to destination. You will end up copying 1.2TB instead of 600GB as what happened to me a few months back. (In my case, I had actual files and symlinks to them in the source directory). If you have links, use rsync.
~Jain
Thanks Jain. Will keep that in mind