57

While I understand how to scp files to and from my server from within my home network, how can I scp a file from my server to my local machine when I am on the outside, say at Starbucks?

While I am able to scp from my local machine to my server in this scenario, I haven't figured out how to grab a file from home, using the command line. Any suggestions?

3 Answers 3

86

The way the question is asked is pretty confusing, but if you can copy from your local machine to the server, to go the other way just flip the command line order.

its scp [from] [to]

scp user@homeip:/path/to/file /local/path/
8
  • Thanks, I'll give it a try and confirm if it worked for me.
    – user98496
    Sep 20, 2011 at 14:10
  • 1
    I think the question is more about setting up dyndns and port forwarding...he just didn't know what to ask. Sep 20, 2011 at 14:22
  • 1
    True, I probably don't know what to ask. I'm still learning. If you could offer further explanation about what ports I need to forward (and any info I'll need regarding dyndns) in order to achieve my goal, I'd appreciate it:-)
    – user98496
    Sep 20, 2011 at 15:31
  • Suggestion in first response did not work. Normally, when I type: "scp -r somedir [email protected]:/home/me/Desktop" it works fine. However, If I try this from a public WIFI connection at say, Starbucks (and not at home), it doesn't work. What am I doing wrong?
    – user98496
    Sep 20, 2011 at 18:59
  • 6
    SOLVED: The command that works for me is: scp remoteusername@host:fileiwanttocopy /my/local/comp
    – user98496
    Oct 19, 2011 at 18:28
40

Copy the file "foobar.txt" from a remote host to the local host:

$ scp [email protected]:foobar.txt /some/local/directory

Copy the file "foobar.txt" from the local host to a remote host:

$ scp foobar.txt [email protected]:/some/remote/directory

Copy the directory "foo" from the local host to a remote host's directory "bar":

$ scp -r foo [email protected]:/some/remote/directory/bar

Copy the file "foobar.txt" from remote host "rh1.edu" to remote host "rh2.edu":

$ scp [email protected]:/some/remote/directory/foobar.txt [email protected]:/some/remote/directory/

Copying the files "foo.txt" and "bar.txt" from the local host to your home directory on the remote host:

$ scp foo.txt bar.txt [email protected]:~

Copy the file "foobar.txt" from the local host to a remote host using port 2264:

$ scp -P 2264 foobar.txt [email protected]:/some/remote/directory

Copy multiple files from the remote host to your current directory on the local host:

$ scp [email protected]:/some/remote/directory/\{a,b,c\} .

$ scp [email protected]:~/\{foo.txt,bar.txt\} .

For More Information: Secure Copy

1
  • And all this requires that you have sshd running - everybody knows that, eh... or not.
    – Hannu
    Dec 15, 2017 at 17:15
0

If you wanted to secure copy to a remote location such as Dropbox or GoogleDrive then create an account with https://couchdrop.io then link your storage provider.

From there simply,

scp <filename> [email protected]:/Dropbox etc, if you then want to pull a file from the cloud then just reverse the two statements so;

scp [email protected]:/Dropbox/filename ~/ - this will pull the file down to your chosen directory

You must log in to answer this question.

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