调用 WinSCP.com 时出现 PowerShell "You must provide a value expression following the '/' operator" 错误

PowerShell "You must provide a value expression following the '/' operator" error when calling WinSCP.com

我有一段代码可以将文件放入 FTP 服务器。看起来像这样:

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

这在 Windows 命令提示符下运行良好,但是当 运行 在 PowerShell 中同样的事情时它不起作用并且 returns 我出现以下错误:

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

我尝试了几种代码组合,但 none 行得通:

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""

由于 winscp.com 可执行文件的路径 and/or 文件名包含空格,因此使用 & 运算符调用它:

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

(当然,假设 winscp.com 的命令行参数在其他方面是正确的)