vbams-accessftpwinscp

Getting "Too many parameters for command", when calling WinSCP command-line from VBA


Upload file via FTP from Excel VBA was very helpfull, I'm using the code to synchronize a local folder to my FTP server.

Call Shell( _
     CurrentProject.Path & "\WinSCP.com /log=" & CurrentProject.Path & "\ftp.log /command " & _
     """open ftp://user:pass@ftp.server.com/"" " & _
     """synchronize local " & localfolder & " /www/remotefolder/wines -filemask=""*.png"" " & _
     """exit""")

I'm trying to issue an exit command at the end, but the code gives me a

Too many parameters for command 'synchronize'.

The line in the log tells me

synchronize local C:\localfolder\wines /www/remotefolder/wines -filemask=*.png exit

The exit is in the same line as the synchronize one, when I use the put script this doesn't happen. What can I do to prevent this?


Solution

  • You are missing closing quote after the synchronize command. And the quotes around -filemask value have to be doubled. Or actually, you do not need them, as the value does not contain spaces.

    This will do:

       """synchronize local " & localfolder & " /www/remotefolder/wines -filemask=*.png""" & _
    

    See https://winscp.net/eng/docs/commandline#syntax


    The symbol you have at the beginning of —hostkey and —rawsettings is not a simple hyphen-minus (-), but em-dash ().

    Please use hyphen-minus (-) — what is the dash that you find on the standard English [and other] keyboards.

    So actually you have the very same problem as in WinSCP forum post you referred to.


    Or even easier, have WinSCP GUI generate a script template for you.

    Also see FAQ Why are some WinSCP scripting commands specified in a batch file not executed/failing?


    Other questions with the same error message, but different problem: