Topic "Too many parameters for option option"

Author Message
Franzi

Guest


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:
Code:

$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:
Code:
[...]
$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?
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?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25946
Location: Prague, Czechia
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
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License