18

I am attempting to copy a file (/home4/user/public_html/website.com/folder_1/folder_2/file_to_copy.zip) from my remote host to my local machine's desktop (/Users/username/Desktop) using the scp command.

In order to accomplish this I run iTerm on my Mac and use the following command:

scp -r [email protected]:/home4/user/public_html/website.com/folder_1/folder_2/file_to_copy.zip /Users/username/Desktop/

(It might also be worth noting that I am logged in via ssh to my remote host as I try to execute this command.)

When I run the command I am prompted to fill in the password for [email protected] (which I do) and then I receive the following error message:

/Users/username/Desktop: No such file or directory

Similarly, I have been unable to use scp to copy files to my remote host.

Any help with this issue is highly appreciated, and I hope that I can receive simple/thorough explanations as I am completely new to using a command line and ssh.

5
  • @n8te So I should not log in to the remote host? Is that the problem? Apr 30, 2017 at 7:11
  • I see, and I find that reasonable since I running this command prompts me to provide the password for [email protected]. When I ran the above command on my local host it timed out. I think this is due to it using the wrong port (22 instead of 2222). How do I change which port it should use when running the command? Apr 30, 2017 at 7:16
  • @n8te Thanks, this completely solved my problem. Apr 30, 2017 at 7:41
  • @n8te please, fill the answer with your findings.
    – Jakuje
    Apr 30, 2017 at 13:54
  • 1
    My problem was a permissions issue on the remote filesystem, once I fixed file permissions, it worked like a charm.
    – james-see
    Jun 8, 2018 at 20:09

1 Answer 1

15

scp does not require that you SSH to the remote computer in order to make the copy (and this is where you're currently running into trouble with your command).

scp essentially works in either a push or pull fashion. You can push files/folders from your local PC to a remote. The command syntax for this method is as follows:

scp /folderpath/tofile/file.txt user@remotehost:/folderpath/tocopyfileto/

Which will prompt you for the password of user on remotehost.

You can also pull file/folders from a remote PC to your local PC. The command syntax for this method is as follows:

scp user@remotehost:/folderpath/tofile/file.txt /folderpath/tolocalfolder/

Which will also prompt you for the password to user on remotehost.

The problem you were running into with your command above is that you were using the data pull syntax of the scp command in order to grab a file from a remotehost, but you were also SSH'd into that remotehost while running it.

The correct way to run this command is to run it from your local machine

scp -P 2222 [email protected]:/home4/user/public_html/website.com/folder_1/folder_2/file_to_copy.zip /Users/username/Desktop/

**Note that I removed the superfluous -r from your original command. It's not something that will throw off an error, but it's just that it's not necessary in your case. The -r option of scp is to be used when recursively copying a folder and all its contents. In your case you were just copying a file so it wasn't necessary.

**I also added the -P 2222 since subsequent comments from you indicated that you needed to use port 2222 instead of standard port 22.

1
  • Very, very strange. I'm trying to push and could not get it to work. But you mentioned being SSHed in to the remote directory causing problems. I was not, but, I copied the non-working command line to the clipboard, completely closed the terminal window to end the session just to make sure and immediately opened a new one, then pasted the command line and hit return, and this time it worked as expected. Weird, but, it works. Must have been some sort of connection lingering in the background. Belated thanks for the tip.
    – John Smith
    Nov 21 at 8:20

You must log in to answer this question.

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