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?


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.

  • If I'd have enough reputation to vote, I would definitely do ;) – Patrick Weiß Mar 5 '16 at 13:03
  • 1
    Might be better to inclue the gzip command server-side to save bandwidth usage. – Jaap Eldering Mar 6 '16 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 '19 at 12:50

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

scp -r username@yourserver.com:/path/to/remote/files /path/to/local/files

-r Recursively copy entire directories.

man scp for full details.

  • If I'd have enough reputation to vote, I would definitely do ;) – Patrick Weiß Mar 5 '16 at 13:03

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

rsync -az username@yourserver.com:/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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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