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?


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.


Don't use pscp.

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

  • 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? Jan 12 '13 at 2:09
  • 1
    @CoreyBurnett: Are you connecting always to the same server?
    – user1686
    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. 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.
    – user1686
    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. 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\."
pscp.exe -pw MyPassword root@ "C:\download files"

well first, as you already mentioned, you have spaces in your path. So it would be wise to use quotes "C:\download files". Second as you already pointed out you need to add your application to your PATH in order to call pscp without any weird path. and third. Use naming conventions that prevent this mess caused by quoting everything.


Both solve the problem, and you look 100500 times cooler.


I was having the same problem, I added the pscp.exe directory as a PATH variable for the session in cmd.exe:

set PATH="C:\Program Files\PuTTY;%PATH"

I had an old Windows netbook that I disassembled for parts. I connected the HDD to my Ubuntu desktop as my only current Windows machine is a laptop, and I didn't want to have to get a SATA to USB adapter. I mounted the HDD correctly and could navigate the files, but when trying to transfer from Ubuntu to Windows 10 using:

pscp user@ "D:\backups

I received multiple errors, including Local to Local copy not supported, Host does not exist, etc.

I was able to get the file to transfer with no problem by using the [OPTION] provided by pscp called -load sessname where sessname is the name of a saved session. The full command was as follows:

pscp -load ubuntu@local user@ "D:\backups

This solved the issue, and using the -load sessname option has worked for every file and directory I've tried to transfer so far, whether I use the user@ipaddress format, or the user@hostname format for the source machine.

Hopefully this helps someone trying to use an Ubuntu machine to restore files from a Windows HDD.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.