从VBA调用WinSCP命令行时获取“命令参数太多” [英] Getting "Too many parameters for command", when calling WinSCP command-line from VBA
问题描述
从Excel VBA通过FTP上传文件非常有用,我正在使用代码将本地文件夹同步到我的FTP服务器。
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""")
我试图在最后发出 exit
命令,但是代码给我一个
I'm trying to issue an exit
command at the end, but the code gives me a
命令'synchronize'的参数太多。
Too many parameters for command 'synchronize'.
日志中的行告诉我
synchronize local C:\localfolder\wines /www/remotefolder/wines -filemask=*.png exit
退出
与 synchronize
处于同一行,当我使用put脚本时不会发生这种情况。我该怎么做才能防止这种情况?
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?
推荐答案
在同步$之后,您丢失了关闭引号。 c $ c>命令。并且
-filemask
值附近的引号必须加倍。或者实际上,您不需要它们,因为该值不包含空格。
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.
这可以做到:
"""synchronize local " & localfolder & " /www/remotefolder/wines -filemask=*.png""" & _
请参见 https://winscp.net/eng/docs/commandline#syntax
在(主机密钥
和 -rawsettings
)开头的符号不是简单的连字符减(-
),但短划线(-
)。
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.
实际上,您遇到的问题与您提到的WinSCP论坛帖子。 或更简单的方法是 WinSCP GUI会为您生成脚本模板。 另请参阅常见问题解答为什么在批处理文件中指定的某些WinSCP脚本命令未执行/失败? Also see FAQ Why are some WinSCP scripting commands specified in a batch file not executed/failing? 其他具有相同错误消息,但问题不同的问题: 这篇关于从VBA调用WinSCP命令行时获取“命令参数太多”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!