Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

JamesEdmondsUKPN

Resolved

I've spent some time getting to grips with the .NET assembly, and am now past the first hurdle of connecting, so I think I'll just proceed with that for now 👍
JamesEdmondsUKPN

Scripting via PowerShell, newbie questions

Hello,

I am writing a PowerShell script to try and automate some file transfers we do via SCP.
I am trying to run the below:
& 'C:\Program Files (x86)\WinSCP\WinSCP.exe' /log="C:\Users\username\WinSCP.log" scp://username:password@hostname /command 'put ""C:\Users\username\OneDrive - CompanyName\Documents\Scripts\PowerShell\Certificates\hostname\hostname-pfxpassword.txt"" /users/home/username/' "exit"


I'm really struggling with the syntax for the file path with spaces in. No spaces in the path works fine, but if I use single, double or double double quotes around the path, I just get errors like this in the log file:
. 2023-02-08 10:46:44.495 File: "\\C:\Users\username\OneDrive"
* 2023-02-08 10:46:44.496 (EOSError) System Error.  Code: 123.
 
* 2023-02-08 10:46:44.496 The filename, directory name, or volume label syntax is incorrect
. 2023-02-08 10:46:44.496 Asking user:
. 2023-02-08 10:46:44.496 File or folder '\\C:\Users\username\OneDrive' does not exist. ("System Error.  Code: 123.
 
. 2023-02-08 10:46:44.496 The filename, directory name, or volume label syntax is incorrect")
< 2023-02-08 10:46:44.496 Script: File or folder '\\C:\Users\username\OneDrive' does not exist.
< 2023-02-08 10:46:44.496 Script: System Error.  Code: 123.
 
< 2023-02-08 10:46:44.496 The filename, directory name, or volume label syntax is incorrect
. 2023-02-08 10:46:44.496 Answer: Abort


When running in PowerShell in this way, how can I correct the syntax to accommodate spaces in the file path?

Additionally, should I be looking to use the .NET assembly instead, and would it help with this kind of automation?

Cheers
James