3

I want to download a folder from a server containing several thousands of files using ssh. I am using Ubuntu and I do not have write permissions on the server, so I am not able to create a .tar on the server and copy it afterwards. But dowloading all files individually is very slow.

So how can I download this folder with that many files as one archive using the command line?

3 Answers 3

2

You could do something like this:

ssh username@hostname 'tar -cf - /dir/to/download' | gzip > remote_files.tgz

This will run tar on the remote server, but instead of writing to a file, it will output to stdout. This will be returned through SSH to your local machine, gzipped and then written to a file.

3
  • If I'd have enough reputation to vote, I would definitely do ;) Mar 5, 2016 at 13:03
  • 1
    Might be better to inclue the gzip command server-side to save bandwidth usage. Mar 6, 2016 at 17:00
  • Concur with Jaap. ssh username@hostname 'tar -cf - /dir/to/download | gzip -9c' > remote_files.tgz might save a lot of bandwidth if you're copying text files or anything easily compressed.
    – Bolwerk
    Sep 29, 2019 at 12:50
3

Both of the previous answers will work, but I'm surprised that no one mentioned rsync, as in:

rsync -az [email protected]:/path/to/remote/files/ /path/to/local/files/

Bonus points is that if the connection is interrupted, you can restart and it will figure out what is left to be copied.

2

Secure copy "scp" is installed with OpenSSH. So this should do the trick...

scp -r [email protected]:/path/to/remote/files /path/to/local/files

-r Recursively copy entire directories.

man scp for full details.

1
  • If I'd have enough reputation to vote, I would definitely do ;) Mar 5, 2016 at 13:03

You must log in to answer this question.

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