Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to download files from a remote server to my local drive, and do it from the command line. I also want to be able to do this over SSH. How can I do this?

Note: the remote server is Ubuntu, the local is Mac OS X

share|improve this question
up vote 28 down vote accepted

Use scp-command, it runs on top of SSH. Example:

scp localfile

It also works another way round

scp localfile username@host:/path/remotefile

Username, path, and filename can be omitted (but not the : !).

As Iain said, SFTP works also, but I tend to favor scp for its cp-like usage.

share|improve this answer
Less common I'm sure, and correct me if I'm wrong, but I think scp also works remote-to-remote, if you really need to: scp username@remote1:/path/to/file username@remote2:/path/to/file – JMD Jan 11 '10 at 22:06
can you copy directories? – Andrew Jan 11 '10 at 22:10
figured it out... -r recursively copies directories too – Andrew Jan 11 '10 at 22:15
I recommend adding the -p option when copying files or folders with scp. It copies over the file attributes too (timestamps and flags). I find I want -p more often than I don't want it! – joeytwiddle Aug 8 '14 at 22:43
You can also remote-to-remote routed through the localhost using the -3 flag: scp -3 This is useful if you need to use a private key for access to both servers only found on localhost: scp -3i /local/path/to/.ssh/private_key dan@host1:/path/to/file.txt miri@host2:/path/to/upload/dir/ The progress bar is disabled for -3 – Dan Sandland Sep 23 '15 at 22:32

You can also use rsync for it. It can work over SSH.

share|improve this answer
rsync -avvP is my favourite for files and/or folders, but there is one drawback: it needs to be installed on the remote machine. – joeytwiddle Aug 8 '14 at 22:44
If you are having trouble connecting, you may need to pass -e ssh to tell rsync to connect over ssh. – joeytwiddle Aug 8 '14 at 22:47

I use SFTP for this. It's command line and uses the same security as SSH.

share|improve this answer

If you can't use scp or SFTP you can use tar over SSH:

tar cf - . | ssh otherhost "cd /mydir; tar xvf -"

This one is also good if you have sparse files which otherwise will "explode".

share|improve this answer

You must log in to answer this question.

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