I'm trying to build log path and lcd variables in my WinSCP script and I don't know the proper syntax to make it work.
How can I put the variables into the script correctly? This is an example of what I'm trying to do.
$logPath = "c:\LogPath"
$lcdPath = "c:\lcdPath"
& "C:\Program Files (x86)\WinSCP\WinSCP.com" `
/log = $logPath /ini=nul `
/command `
"open ftpSite -hostkey=`"`"hostKey`"`" -rawsettings FSProtocol=2" `
"cd ftpFilePath" `
$lcdPath `
"get * -filemask=*>=1D" `
"exit"
CodePudding user response:
Your syntax for using variables is correct. It's your WinSCP command-line syntax that is wrong.
There should be no spaces around switch values. And the values should better be quoted, in case they contain spaces:
/log="$logPath"
The
/log
takes path to a file, not path to a directory:$logPath = "c:\LogPath\WinSCP.log"
You are missing the actual
lcd
command:"lcd $lcdPath" `
The only PowerShell issue I see in your code is that the backtick that is meant to escape a line end, has to be the last character on the line. While you have spaces after the backtick in the
WinSCP.com
line:& "C:\Program Files (x86)\WinSCP\WinSCP.com" `#no spaces here