views:

25

answers:

1

Hello,

I can't seem to be able to convince scp to behave.

For test data

ubuntu@domU-12-31-38-00-D4-F1:/tmp$ find /tmp/a1/
/tmp/a1/
/tmp/a1/a2
/tmp/a1/a2/a3

On issuing the command

ubuntu@domU-12-31-38-00-D4-F1:/tmp$ scp -r /tmp/a1 domU-12-31-38-00-E2-52.compute-1.internal:/tmp/a1

I would expect the same directory structure created on domU-12-31-38-00-E2-52.compute-1.internal, whatever the directory /tmp/a1 exists on target host or not. Instead, what scp actually creates is the following structure (if /tmp/a1 exists on target host)

ubuntu@domU-12-31-38-00-D4-F1:/tmp$ ssh domU-12-31-38-00-E2-52.compute-1.internal find /tmp/a1 
/tmp/a1
/tmp/a1/a1
/tmp/a1/a1/a2
/tmp/a1/a1/a2/a3

How can scp be forced to copy into given directory as the root of the operation?

Later on I would like to script this operation so that given directory path on master I can call a script that will replicate the same directory structure to all slaves. Please note that rsync behavior (at least from what I've tested) is the same in this manner.

Thank you, Maxim.

+2  A: 

scp is mimicking the behavior of cp, which is to copy INTO the target directory (if it exists). Just have it copy into /tmp rather than /tmp/a1.

John Kugelman
I don't think it will work in all cases as a general copying to slaves utility. Your suggestion means I will need to find absolute path for a parameter, then decide if it's a directory or not. If it is then strip one level up before constructing the scp command. Isn't there a more simple solution that is "scripting friendlier?"
Maxim Veksler
You can strip one level up for files, too. I don't think it needs to be conditional. `dirname` will do this for you. You'll need to be careful about slashes at the end of the path.
John Kugelman