How do I SCP from remote machine to local machine?

2

I know there are some similar questions has been asked here and I did read them... however, I still can not copy a file from a remote machine down to my local computer... I am keep getting error like "No such file or directory"

Here is what I do. I open terminal on MacOS, log in to the remote machine, cd to the folder I want. Now, under this folder I have a .txt file, say "error.txt", and I want to copy this file down to my local desktop.

I get the directory for my local desktop by just drag the desktop folder into the terminal and I got a path /Users/myname/Desktop

Then I tried the following commands (while under the folder the error.txt is inside the remote machine):

scp -r error.txt /Users/myname/Desktop

or some variations

scp -r error.txt :/Users/myname/Desktop
scp -r error.txt ~/Users/myname/Desktop
scp -r error.txt Users/myname/Desktop

but all of them are keep giving me the error like

cannot create regular file `/Users/myname/Desktop': No such file or directory

Maybe my trouble is how to correct write my local path? But I can cd to my local desktop by using the path /Users/muname/Desktop while inside my local machine...

Any helps? Thank you!

JumpJump

Posted 2016-10-24T14:08:27.170

Reputation: 123

Answers

4

You are doing it wrong:
In Terminal DON'T login to the remote machine.
Just run:

scp user@remote:<path>/error.txt /Users/myname/Desktop 

In other words: Run SCP locally on your Mac and tell it to retrieve the file from the remote machine. When you are already logged in on the remote machine you need to scp from local (which is the remote machine in that case) to a remote machine (which is your Mac in that case).

Tonny

Posted 2016-10-24T14:08:27.170

Reputation: 19 919

that works! Thank you. But can you explain to me that why I need to run SCP locally? I am asking this because when I copy my file from my local machine up to remote machine. I am operating inside my local machine and using SCP to send the file up. So I though when I try to copy down the file, I should go up to remote machine and use SCP to send the file down... – JumpJump – 2016-10-24T14:50:19.853

You don't have to run it locally, it's just easier. Essentially, you run it wherever your shell is, and the first shell you see is on your local system. – Christian – 2016-10-24T15:07:11.937

1@JumpJump SCP can copy between local<->local, local<->remote, remote<->local and remote<->another remote. Just a matter of specifiying source and destination properly. But in every case, for remote you need to supply the full path, including login credentials to the remote system. There is no need to get a shell first on the remote and then copy it back. It's just extra hassle. – Tonny – 2016-10-24T18:06:03.313

2

You need to provide the path of the remote machine - you would run this on your local machine, ie the one you want to save the file TO.

scp remoteuser@remote.machine.com:/path/to/file/on/server /path/to/save/file/locally

djsmiley2k TMW

Posted 2016-10-24T14:08:27.170

Reputation: 5 937

1Indeed: And do that on the MAC. Not on the remote machine. – Tonny – 2016-10-24T14:16:25.623