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

Posted by Elina Uphoff on Thursday, May 2, 2024

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

1 Answer

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)

2

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoa3BuY22EdIOOqaawnaKotaa4y2awqK1dosK0wIypqaiumZmybq2Mr5ilrZVisrm80Z6qrKGfo3qnu8ulprChnpx6tbTEZqapnaKWwbC%2BjJ6pq6c%3D