2

Supposing we have the following files to copy to a remote server:

/dir/test.php
/dir/inc/inc.php

I now want to copy both files to the remote server as follows:

cd /dir/
scp test.php inc/inc.php user@remote:/dir2/ (which contains an inc folder)

Is there an option to make scp copy the files in the respective directories on the remote server?

Currently I would end up with both files in /dir2/ on the remote server.

1 Answer 1

4

Yes. Manual page provides information about usage of scp command and it mentions also the -r switch, which means "recursive". You can achieve the same such as:

scp -r dir/ user@remote:/dir2/

Update

For more complicated use cases, use rsync, something like this:

rsync --include="test.php" --include="inc/inc.php" ./dir/ user@remote:/dir2/
3
  • 1
    Sure but I need to apply to files and not directories. If I have a directory with 1000 files I don't want to copy all of them. Feb 2, 2016 at 19:40
  • 3
    so if you have more specific selection, you should check out rsync. scp is really only simple tool.
    – Jakuje
    Feb 2, 2016 at 19:41
  • 1
    Also it is not obvious from your question. If you ask for something different, clarify.
    – Jakuje
    Feb 2, 2016 at 19:47

You must log in to answer this question.

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