0

The following scp is working as expected.

scp /home/admin/* root@ec2-50-112-212-73:/

But I need a command that will create the required folder structure on destination server if it does not already exist.

Update:

I can do it in 2 steps as shown below. I will like to know if there is any other way.

ssh root@ec2-50-112-212-73  " mkdir -p /home/admin/ "
scp  -r /home/admin/* root@ec2-50-112-212-73:/home/admin/
3
  • 4
    Do you mean scp -r?
    – quanta
    Jun 26, 2012 at 11:00
  • No. equivalent to mkdir -p /home/admin/ on remote server, that will work with scp or tar
    – shantanuo
    Jun 26, 2012 at 11:07
  • That's what -r for: Recursively copy entire directories. Note that scp follows symbolic links encountered in the tree traversal.
    – ott--
    Jun 26, 2012 at 11:23

2 Answers 2

1

You might be better off using rsync:

rsync -av -R -f"+ */" -f"- *" /home/admin/* root@ec2-50-112-212-73:/

This will only create the directories on the other (ec2) side

2
  • Wouldn't you also need the -R option in order to create /home/admin/?
    – Oliver
    Jun 26, 2012 at 11:20
  • Ah, yes, thought he didn't want that. Thanks. Jun 26, 2012 at 11:24
0

scp -r /home/admin/ root@ec2-50-112-212-73:/home/admin/ will work, assuming you don't specifically want to copy just the non-dotfiles in /home/admin.

Not the answer you're looking for? Browse other questions tagged .