1

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"

1 Answer 1

2

Your syntax for using variables is correct. It's your WinSCP command-line syntax that is wrong.

  1. There should be no spaces around switch values. And the values should better be quoted, in case they contain spaces:

    /log="$logPath"
    
  2. The /log takes path to a file, not path to a directory:

    $logPath = "c:\LogPath\WinSCP.log"
    
  3. You are missing the actual lcd command:

    "lcd $lcdPath" `
    
  4. 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
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.