Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Damn! I was going to suggest rsync! –  Nathan Fellman Mar 4 '10 at 8:53

4 Answers 4

up vote 16 down vote accepted

use 'tar'

 tar cvzf - -T list_of_filenames | ssh hostname tar xzf -
share|improve this answer
    
Great! This is what I needed!!! –  Peter Smit Mar 4 '10 at 10:35
1  
Heres the file format: "In c mode, tar will read names to be archived from filename. The special name -C'' on a line by itself will cause the current directory to be changed to the directory specified on the following line. Names are terminated by newlines unless --null is specified. Note that --null also disables the special handling of lines containing -C''." –  Kousha Mar 4 '10 at 10:46

I would like to use scp for that, but scp only allows for transferring one file at a time.

I'm pretty sure that isn't true, at least not for the scp command provided by the OpenSSH included with most Linux distributions.

I use scp file1 file2 ... fileN user@host:/destination/directory/ fairly frequently.

share|improve this answer
    
This is the right answer, but it really only transfers one file at a time. Nevertheless it will make full use of available bandwidth and should run as fast as possible. –  Benjamin Bannier Apr 28 '11 at 19:01

Doesn't scp -r yourdir otherhost:/otherdir work?

Try this then:

tar cfz - . | ssh otherhost "cd /mydir; tar xvzf -"

the z-flag to tar does compression. Or you can use -C to ssh:

tar cf - . | ssh -C otherhost "cd /mydir; tar xvf -"
share|improve this answer
    
what does -C do? –  Nathan Fellman Mar 4 '10 at 8:53
    
The problem is, I have a list of files. The files are spread out over a lot of directories, and not all the files in the directories I want to copy –  Peter Smit Mar 4 '10 at 9:34
1  
@Nathan: -C is to lett ssh do the compression. –  Jimmy Hedman Mar 4 '10 at 11:32

On RHEL5, here is the only way possible that I know of to secure copy a list of files that contain special characters (like a space). Make a shell script and include the following:

FILE="/path/filename"
while read line; do
scp "$line" username@servername:/destination/
done < $FILE
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.