0

I want to scp several files from one computer to other.

The command are:

scp -r file1 file2 com2@ip:dir1
scp file1 file2 com2@ip:dir2

How can I

scp -r file1 file2 file1 file2 to Dir1 & Dir3 

on other computer or is there any other command?

Thanks.

Onel Sarmiento
  • 1,608
  • 3
  • 20
  • 46
gaurav
  • 1
  • 1

1 Answers1

0

You are on the right track, but I would recommend rsync instead of scp (both will work, rsync just enjoys more current development than scp). When copying multiple source files, if they are not the only files in a directory, you can use wildcards with rsync to perform the transfer. In your case you will have to invoke rsync twice to copy to both Dir1 and Dir3 as the destination (otherwise the destination is ambiguous -- it is the same for scp):

rsync -uv file** user@ip:/Dir1
rsync -uv file** user@ip:/Dir3

Note: you can substitute host.domain.tld for ip above. Also note that wildcards with rsync are not the same as your normal wildcards used with your shell. You normally must provide a double ** for rsync to treat it as a wildcard.

With scp you can use your normal shell wildcards and other brace and character expansion for the transfer which can help you narrow the files to transfer:

scp file[12] user@ip:/Dir1
scp file[12] user@ip:/Dir3

To transfer only file1 and file2 to Dir1 and Dir3 at the remote ip.

David C. Rankin
  • 81,885
  • 6
  • 58
  • 85