9

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

2
  • 1
    SSH (and thus also scp) interpretes a colon as a separator between host and path on the host. Thus you have to escape the colon. On Linux you'd normally do this by prefixing it with a backslash: \:, but I don't know how this should work on windows. FYI: neither source nor destination contains a remote hostname, this seems something else you need to fix too. Commented Sep 18, 2016 at 15:09
  • 1
    It looks like you invoke scp on the server. You should run scp or equivalent tool on your local computer unless your Windows is also SSH server (but even in this case initiating the connection from Windows seems more natural). I advise you to investigate MobaXterm "built in file transfer pane" mentioned here. Commented Sep 18, 2016 at 15:19

4 Answers 4

10

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.

2
  • 1
    The GUI option is simple and exactly what I needed Commented Sep 17, 2021 at 8:45
  • It's worth noting that using the GUI you can only upload files, if you want to directly upload a folder altogether, you can only do that using drag and drop. As far as I tried. Commented Jul 18 at 8:47
1

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.

1

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:

  1. foo/bar/...: means that foo is a directory (folder) visible from your path, it may be you current path (pwd) or in the path env variable (echo $PATH).

  2. /foo/bar/... means that foo 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.

0

In windows the following command worked for me :- scp -r "Reqd.Folder name in quotes" username@remote_server:File path at server

scp -r "ABC" shivam@remote_server:/media/External/shivam.

Move to the folder before executing it where the required folder is present

You must log in to answer this question.

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