Linux – How to copy multiple files over scp in one command

linuxscpssh

I have to transport a lot of files from one PC to another (both Linux). I would like to use scp for that, but scp only allows for transferring one file at a time.

How can I do this?

I have

  • No possibility to use rsync or any other protocol
  • No possibility to use passphrase-free certificates (but have a certificate with a passphrase)
  • A list of files to transfer and a list with the destination path of the files on the other server
  • The files are spread out over a lot of directories, and not all the files in the directories I want to copy

If possible, I would like to gzip and ungzip transparently to save bandwidth!

Is this possible?

Best Answer

Use tar:

tar cvzf - -T list_of_filenames | ssh hostname tar xzf -