Using SSH instead of SCP

Using the program SCP is not needed, use this scipt to use SSH for transferring files:

$ ssh [email protected] "cat /remote/file" > /local/file

To use this trick in a shell script-wrapper:

$ cat
#!/bin/sh -x

host=$(echo "$1" | cut -d@ -f2 | cut -d: -f1)
user=$(echo "$1" | cut -d@ -f1)
remotefile=$(echo "$1" | cut -d: -f2)

if [ ! "$host" -o ! "$user" -o ! "$remotefile" -o ! "$localfile ] ; then
echo "Please use all requires options, for example:"
echo "$0 [email protected]:./file ."
exit 1

ssh $host "cat $remotefile" > $localfile
$ chmod 755

Now "replace" the normal SCP by using an alias:

$ alias scp="~/"

One flaw of this script is that all options will have to be configured statically in .ssh/config.


I am using two servers with

I am using two servers with different operating systems in them when ever I thought of using SSH with SCP it is showing error and not allowing me to use any one of these, and i referred bestessay blogs too. If I uninstall the SCP than SSH it is working fine and my work is going smooth and I able to transfer data from one server to another also. Why this happening like this I am not able to understand.

It may be hard to understand

It may be hard to understand at first, yet, it is very interesting to know this. - Morgan Exteriors

You can also use ssh to make

You can also use ssh to make a dd image of your harddisk:

dd if=/dev/sda \
| ssh [email protected] \
'cat - > /opt/vmware/oldserver/oldhd.dd'


Just one question: why? Why

Just one question: why? Why shouldn't I use scp when needed. With your wrapper and an alias I still have to type scp so what's the diff? Furthermore your script doesn't include any additional options like specifying different port number. And what if I have a SCP/SFTP account with interactive console access disabled? The normal scp will work while yours wont.

So, tell me why?

Quite right, the only answer

Quite right, the only answer I can think of; because SCP sometimes is not compatible over two different servers. So; when SSH works, but SCP fails, this script could be helpful.

About Consultancy Articles Contact

References Red Hat Certified Architect By Robert de Bock Robert de Bock
Curriculum Vitae By Fred Clausen +31 6 14 39 58 72
By Nelson Manning [email protected]