Too many parameters for option option

Advertisement

Franzi
Guest

Too many parameters for option option

Hi,
Im currently scripting a backupscript in Powershell. Unfortunately I get the error "Too many parameters for option option". Going through the forum it often was an outdated WinSCP-version or simple misspelling or wrong characters. I can't see any of that in my case though, maybe you can see?

Here's my script:
$BackupSource= "D:\Data\stuffandthings\"

$FTPserver   = "123.456.789.012"
$FTPport     = "21"
$FTPuser     = "Username"
$FTPpassFile = "credentials.txt"
$FTPpass     = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR((Get-Content $File | ConvertTo-SecureString)))
$FTPcert     = "12:12:12:12:aa:aa:aa:aa:bb:bb:bb:bb:22:22:22:33:33:33:22:11"
$FTPurl      = "ftps://"+$FTPuser+":"+$FTPpass+"@"+$FTPserver+":"+$FTPport

$WinSCP  = "WinSCP.com" #path to WinSCP.com
$WinSCParg = @"
open "$FTPurl" -explicit -certificate="$FTPcert"
option batch abort
option confirm off
synchronize remote "$BackupSource" "/" -delete -resumesupport=on -preservetime -criteria=either
close
"@ #> "script.txt"

& $WinSCP -command $WinSCParg >> $LogFileCurrent
#& $WinSCP -script="script.txt" >> $LogFileCurrent
#del "script.txt"
as you can see in the end of the script I experimented with using a scriptfile, which once uncommented works just fine, like this:
[...]
$WinSCP  = "WinSCP.com" #path to WinSCP.com
$WinSCParg = @"
open "$FTPurl" -explicit -certificate="$FTPcert"
option batch abort
option confirm off
synchronize remote "$BackupSource" "/" -delete -resumesupport=on -preservetime -criteria=either
close
"@ > "script.txt"

& $WinSCP -script="script.txt" >> $LogFileCurrent
del "script.txt"

unfortunately if I write my password into this scriptfile in plaintext all my effort of scripting this leads to a security issue, which I don't want.
Does anybody see my error?

Reply with quote

Advertisement

Franzi
Guest

a little Update:
I found out, that writing the script-string into a file and instantly re-reading it into another string and deleting the file again solves the problem. So WinSCP doesn't like something about the first string. Does anybody have an idea why it won't accept the string?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,552
Location:
Prague, Czechia

Re: Too many parameters for option option

If you want to provide commands on command-line, you have to quote individual commands and pass them as a single line. Like
$WinSCParg = @""open ""$FTPurl"" -explicit -certificate=""$FTPcert""" "option batch abort" "option confirm off" ..."@
(not tested)
See https://winscp.net/eng/docs/commandline#scripting

Your finding from your second post does not make any sense.

Anyway, you better use WinSCP .NET assembly:
https://winscp.net/eng/docs/library_powershell

Reply with quote

Advertisement

You can post new topics in this forum