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.

Fabrizio Mazzoni
  • 671
  • 1
  • 9
  • 24

1 Answers1

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/
Jakuje
  • 9,715
  • 2
  • 42
  • 45
  • 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. – Fabrizio Mazzoni Feb 02 '16 at 19:40
  • 3
    so if you have more specific selection, you should check out `rsync`. `scp` is really only simple tool. – Jakuje Feb 02 '16 at 19:41
  • 1
    Also it is not obvious from your question. If you ask for something different, clarify. – Jakuje Feb 02 '16 at 19:47