Linux – How to correctly copy a folder from the local computer to the server using SSH? Why the scp command go into an error

linuxmobaxtermputtyscpssh

I am logged into my web server via SSH using a tool named MobaXterm (it is someting like Putty but with advanced feature, this is not so important…)

My problem is that I want to send a directory from my local computer (Windows) to a specific directory of this server (Linux).

So I have try to use the scp command as shown here: http://www.hypexr.org/linux_scp_help.php

I have done in this way:

-jailshell-4.1$ scp -r C:\Users\Andrea\Documents\Betrivius\candycane-0.9.6\candycane /home6/XXX/public_html

ssh: Could not resolve hostname C: Name or service not known

But, as you can see, I obtain an error.

Why? What am I missing? How can I fix this issue?

Tnx

Best Answer

Presumably you are running this in a local MobaXterm shell (i.e. local to the windows machine). If that is the case, you need to update the scp command syntax to accommodate that environment, although the syntax is incorrect regardless.

MobaXterm provides access to local drives in it's shell via the mountpoint /drives/X, with X being the windows drive letter.

Additionally, the (simplified) general syntax of scp, regardless of environment is:

scp usage:

scp [[user@]host1:]/path[/filename] [[user@]host2:]/path/[filename]

The first sequence ([[user@]host1:]/path[/filename]) is the 'FROM' section; the source of the file or files to be copied. The second is the 'TO'; the destination. The brackets indicate optional arguments.

It is really just an ssh enabled version of the standard cp command; with the section prior to the : containing the ssh specific information, and the info afterwards pertaining to the cp operation.

user:

user defaults to your current, local username - it can be left out if that is the correct user name in both the source and destination.

host:

host defaults to the local computer (localhost); so if you are copying to / from the local machine AND the username on localhost to be used is the current user, you can omit that argument for the local file(s).

file / path:

path/filename defaults to the specified users home directory and it can be omitted if that's desired. filename can be left out when doing a recursive copy as in your situation - just provide the path in that case. Generally the full path and filename is specified in the FROM section, and just the path in the TO section (it will default to keeping the same filename).

I'm using remoteuser and remotePC as the username and remote PC host name; replace with the correct names.

Correct syntax in your example:

 scp -r "/drives/C/Users/Andrea/Documents/Betrivius/candycane-0.9.6/candycane" remoteuser@remotePC:/home6/XXX/public_html

Use the command man scp or this site for additional details (arguments, other usage info).

GUI Option

Alternatively, MobaXterm provides a graphical file browser (built on sftp or scp based on configuration options) which provides drag and drop bi-directional file transfers when you have connected to the remote host via ssh. Details here.

Related Question