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 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

4 Answers 4

up vote 22 down vote accepted

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

scp username@remote.host:/path/to/file 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 at 22:43

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 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 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

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.