How can I correctly copy a folder from my local computer to my server using SSH? Why the scp command go into an error?
Solution 1:
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.
Solution 2:
Unless that webserver has a way to connect directly to your Windows machine (on port 22 which will require an SSH daemon to be running as well as ports being forwarded), you will need to invoke SCP from the Windows side. MobaXTerm is an ssh client, I'm not sure if it has SCP built in ( I don't personally use it), but the best solution here is use a SCP client, whether it be a command line client or a GUI client.
A rather popular client for windows is WinSCP, it is my goto client when I have no choice but to use Windows.
Solution 3:
To answer
Why the scp command go into an error?
, the error being
ssh: Could not resolve hostname C: Name or service not known
, and the command used being
scp -r C:\Users\Andrea\Documents\Betrivius\candycane-0.9.6\candycane /home6/XXX/public_html
I would say:
the syntax C:\Users\....
is wrong. In this context you have two possibilities to describe a path:
foo/bar/...
: means thatfoo
is a directory (folder) visible from your path, it may be you current path (pwd
) or in the path env variable (echo $PATH
)./foo/bar/...
means thatfoo
is a directory (folder) present at the root of your file system.
As you used the first option (because there is no "/" before "C:"), the shell search for C:
in the path, but can't find it. Consequently it tries to match another syntax: [user@]host1:/path/..../filename
. In this situation ssh complains because it can't find an IP address for C:
(because it thinks that C:
is the host name). Finding an IP address corresponding to a host name is called "hostname resolution"; here this resolution fails, so you understand the error.