How to use PSCP to copy file from Unix machine to Windows machine where target path has spaces?
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 [email protected]:/etc/myfolder/myfile.opt "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 [email protected]:/etc/myfolder/myfile.opt "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.