I am using scp to copy a directory from one remote server to a new directory (IE just changing the name) on another remote server like:
scp -prq server1:dir1 server2:dir2
This works fine if dir2 does not exist on server2, it creates a new directory called dir2 which contains everything from dir1 on server1.
The problem comes when dir2 already exists on server2 (NOTE: I have no way of knowing this in advance or of doing a remove on dir2 on server2 beforehand) - what happens is I get a copy of dir1, called dir1, in dir2.
Here is a script that works for me:
#!/bin/sh
echo "method 1"
scp -prq server1:dir1/* server2:dir2/ >/dev/null 2>&1
if [ "$?" -ne "0" ]; then
echo "failed ... trying method 2"
scp -prq server1:dir1 server2:dir2
fi
exit
Still not sure how to do this in a single command or even if possible.