“No such file or directory” error when attempting to copy (using scp) from remote host to local machine

command lineremote desktopscpssh

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 user@remotehost.com:/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 user@remotehost.com (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.

Best Answer

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 user@remotehost.com:/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.

Related Question