2

I'm using plink on a windows 7 desktop to create a folder a on windows 2008 server. The server uses pragmaSSH to allow the SSH connection and everything works just fine there.

The directory I want to create has a space in it and that is where my problem starts.

I have a basic plink command that works like this

plink.exe -i privatekey.ppk user@server cmd.exe /c mkdir "c:\asdfasdf"

but changing that command to this fails. so the space is for sure my issue.

plink.exe -i privatekey.ppk user@server cmd.exe /c mkdir "c:\asdf asdf"

I've tried to escape this in every possible way I can think off and always get the same problem with the space.

Ok after 60000 tries i figured out how to pass the quotes to the server.

plink.exe -i privatekey.ppk useryserver mkdir \\"""c:\asf asf\\"""

and that sent the 1 quote on each side and ran the command as mkdir "c:\asf asf"

1 Answers1

2

The quotes are just enough to escape the command for plink which is not smart enough to quote again on the other side (reasonable, since it cannot know what weird shell might run there).

So you need the following:

plink.exe -i privatekey.ppk user@server cmd.exe /c mkdir "\"c:\asdf asdf\""
Joey
  • 344,408
  • 85
  • 689
  • 683
  • that also gives the same problem, it tries to still create just the asdf folder. A subdirectory or file c:\asdf already exists. Error occurred while processing: c:\asdf. A subdirectory or file asdf already exists. Error occurred while processing: asdf. – johnnydeluxable Jul 19 '11 at 12:16
  • @johnnydeluxable: Possibly, different ways of escaping the quotation mark should be applied in different situations. One is as in @Joey's answer, others are: `"^"c:\asdf asdf^""`, `"""c:\asdf asdf"""`. – Andriy M Jul 19 '11 at 12:42
  • It is also possible that the entire `mkdir` command (including the argument) should be enclosed in double quotes, with escaping the double quotes around the folder name. – Andriy M Jul 19 '11 at 12:45
  • i tried with """, "\", "^" with mkdir in and out of the quotes, all the same thing plink always removes too many quotes and it slways tris to just make c:\asdf no matter how i pass it i get the same result as if i had not put any quotes of any kind. – johnnydeluxable Jul 19 '11 at 13:35
  • 1
    I tried with a FreeBSD host on the other end and `\"` worked. The reason why I think that that's the correct way to escape the quotes is is that on Windows programs are responsible for parsing their own command line. This includes things like quotes. Therefore, the first level of quotes will be stripped by `plink` itself which then passes what remains on to the other system (with the `\` in that case removed). Shell quoting isn't necessary in any place as far as I can see, since there is no shell somewhere that will remove quotes. Unless I'm overlooking something here. – Joey Jul 19 '11 at 14:03