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 copy a file (home/remote_computer_user/Desktop/test1.txt) from my remote office computer (a permanent URL + open port) to my home computer (home/home_computer_user/Downloads/).

How can I do this with shell commands in Linux?

My current thoughts:

  1. ssh <user>@<computer1address> -p <port> - gives me a shell on the remote computer
  2. (I think I should use scp, but I dont how exactly how in my case)

What are the exact commands I should use?

share|improve this question << this should help you – Anarko_Bizounours Jun 23 '11 at 15:40
If you do this regularly, you might want to look into the rsync command. – TMN Jun 23 '11 at 16:13
You seem to be missing a few /s in your paths (as in "/home/remote_computer_user"). – grawity Jun 23 '11 at 19:25
the rsync is not the solution here. rsync will syncrhonize 2 directories, but he want to copy file in a secure way, so scp. Using rsync in this case will only be bothersome, and might be quite awkward for only copying file. If it's for a backup then, yes, rsync is the most appropriate way. If it's only to recovering data, scp will do the trick. – Anarko_Bizounours Jun 24 '11 at 6:52
Also I think he will never be able to do it until he create NAT on his home internet router and having dns record. (like dyndns) – Anarko_Bizounours Jul 5 '11 at 9:18

It should be something like:

scp -P <port> user@comp1:Desktop/test1.txt ~/Downloads/

Run this on your home PC.

Hope this will help you.

share|improve this answer

scp works, but you can also use rsync:

rsync -e 'ssh -p <port>' <user>@<computer1address>:Desktop/test1.txt ~/Downloads/

Most of the time rsync is a drop-in replacement for scp, i.e. with most scp commands you can just replace scp with rsync and it will work the same way. The only reason that isn't true for your case is that rsync doesn't have a -p option to specify the port (well, it does, but it only applies when rsync connects through its own native protocol, not over ssh). So you need to tell it to use an alternate ssh command that includes the port.

If your ssh server uses the standard port, or if you have the port configured in ~/.ssh/config (in either case, this means you don't need to use the -p option when connecting with ssh), then you can just run

rsync <user>@<computer1address>:Desktop/test1.txt ~/Downloads/

In general, I prefer rsync to scp because it has many more options, and because if you're transferring a large number of files, rsync has the sense to skip ones that already exist on the destination system, cutting down on the amount of data that has to be transferred.

share|improve this answer

If you have FTP or SCP, use it. It's more comfortable. If you are limited to ssh (like I am on many embedded systems)

Upload single file:

 ssh login@remotehost -p remoteport "cat >filename" <filename

Download single file:

 ssh login@remotehost -p remoteport "cat filename" >filename

Upload a directory

 tar -cf - dirname | ssh login@remotehost -p remoteport "tar -xf -"

Download a directory

 ssh login@remotehost -p remoteport "tar -cf - dirname" | tar -xf - 

Instead of dirname you can specify multiple files, directories or a pattern to match. Watch out for absolute paths.

share|improve this answer

An alternative to scp that may be more familiar and is more suitable for multi-file transfers is sftp. It comes with all major versions of ssh that I've encountered.

share|improve this answer

You must log in to answer this question.

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