7

I have a piece of code that puts a file into an FTP server. Looks like this:

"C:\Program Files (x86)\WinSCP\WinSCP.com" /command "open user@myFTPServer:MyPort/MyPath/ -privatekey=myprivatekey.ppk" "put myfile.txt" "exit"

This runs fine in the Windows command prompt, but when running the same thing in PowerShell it doesn't work and returns me the following error:

"You must provide a value expression following the '/' operator"

I've tried a few combinations of my code but none of them worked:

1)

"C:\Program Files (x86)\WinSCP\WinSCP.com" -command "open user@myFTPServer:MyPort/MyPath/ -privatekey=myprivatekey.ppk" "put myfile.txt" "exit"

2)

"C:\Program Files (x86)\WinSCP\WinSCP.com" -command ""open user@myFTPServer:MyPort/MyPath/ -privatekey=myprivatekey.ppk" "put myfile.txt" "exit""
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Victor
  • 1,163
  • 4
  • 25
  • 45

1 Answers1

20

Since the path and/or filename of the winscp.com executable contains whitespace, invoke it with the & operator:

& "C:\Program Files (x86)\WinSCP\WinSCP.com" /command "open user@myFTPServer:MyPort/MyPath/ -privatekey=myprivatekey.ppk" "put myfile.txt" "exit"

(assuming the command-line arguments to winscp.com are otherwise correct, of course)

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62
  • Thanks for your answer. Now it's working, but it won't get my ppk because it's under a path with white spaces. I tried adding "&" right after -privatekey but it doesn't work. Any idea how to fix this? – Victor Dec 04 '17 at 17:42
  • @Victor Your question does not show any path with spaces. But this will probably help you: [Use path with spaces in batch file using WinSCP](https://stackoverflow.com/q/46154795/850848) – Martin Prikryl Dec 04 '17 at 17:47