Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having a problem using PSCP in a C# program to copy a file from a Unix machine to a Windows machine. The problem only happens when the target folder on the Windows machine has a space in it. For example, the following works fine: (NOTE: the IP address and password have been changed for this example)

pscp.exe -pw MyPassword root@ C:\download

But when I change it to this:

pscp.exe -pw MyPassword root@ C:\download files

I get the following error: More than one remote source not supported.

I realize that is because PSCP inteprets the space as another target. But how can I do it? I have tried all kinds of things like putting it in quotes and escaping the space. I have tried all of the following and nothing works:

pscp.exe -pw MyPassword root@ "C:\download files"
pscp.exe -pw MyPassword root@ C:\"download files"
pscp.exe -pw MyPassword root@ C:\download\\ files

Any ideas?

share|improve this question
up vote 7 down vote accepted

Although the proper answer is probably to use WinSCP and their C# library, I did find a way to get PSCP to work when the target folder has a space in it.

The correct answer is to do this:

pscp.exe -pw MyPassword root@ "C:\download files"

It turns out that I was having another problem that was making me think the above was not working. Originally I was using the full path to the PSCP.EXE executable. The full path included spaces. So I was trying to do the following:

"C:\My PSCP Folder\pscp.exe" -pw MyPassword root@ "C:\download files"

And I was trying to call that from C# using Process.Start() and it was failing. It seemed like it could handle it if there was a space in either the PSCP path or the target path, but not both. I fixed that by including the path to the PSCP executable in my Windows Environment variables. Now I am able to just call PSCP.EXE and it works with the quotes around the target folder.

share|improve this answer

Don't use pscp.

The WinSCP client (which is built on top of PuTTY) provides a .NET assembly. Here's an example.

share|improve this answer
Well I looked at that and I ran in to a different problem. Apparently WinSCP requires the SSH Host Key (which I don't have). When I was using PSCP there was a way to automate the acceptance of the Host Key. But from what I can tell in reading the WinSCP C# documentation there doesn't seem to be any way to automatically accept the Host Key. Any ideas? – Corey Burnett Jan 12 '13 at 2:09
@CoreyBurnett: Are you connecting always to the same server? – grawity Jan 12 '13 at 2:12
I'm building an application that will be installed on a Windows machine and will potentially connect to a number of different Linux servers. When I was using PSCP I found a way to tell the command line to automatically accept the Host Key. That way I didn't need to know what the Host Key was ahead of time. However I can't seem to find that option using C# and WinSCP. – Corey Burnett Jan 12 '13 at 2:39
Personally, I would consider it a serious security issue if an SSH client was accepting host keys without verification or user confirmation. – grawity Jan 12 '13 at 10:40
I agree. However this is a very specific situation where we are building an application that will be installed on a laptop and then that laptop will be connected to a Unix box in a controlled environment. This setup will be sold to customers. It is not even connected to the Internet. I am just trying to make it simple to install and use so that the operator of the application doesn't have to know or worry about the Host Key stuff. It should just work. – Corey Burnett Jan 12 '13 at 16:02

Append a period to the destination folder. The following should work with the appended . on your example:

"C:\My PSCP Folder\pscp.exe" -pw MyPassword root@ "C:\download files\."
share|improve this answer

You must log in to answer this question.

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