【问题标题】:Managing special characters in batch script to write WinSCP "open" connection string [duplicate]管理批处理脚本中的特殊字符以编写 WinSCP“打开”连接字符串 [重复]
【发布时间】:2020-05-11 06:21:32
【问题描述】:

我正在尝试编写批处理代码以将脚本生成到文件中,以打开与 WinSCP 的连接;最后的命令应该是这样的:

open sftp://user:password@example.com/

密码包含+ 符号,我必须将其更改为%2B 才能让WinSCP 理解。

set pw=mypassword+
::echo %pw% return--> mypassword+
set st=%%2B
::echo %st% return--> &2B
call set pw=%%pw:+=%st%%%
::echo %pw% return--> mypassword2B

我找不到最后一次调用返回%pw%=mypassword%2B%2B 之前)传递给 WinSCP 脚本的方法。你能帮我吗?或者是否有另一种策略(但始终在批处理文件中)使 WinSCP open 命令接受正确的密码?提前致谢。

【问题讨论】:

    标签: windows batch-file cmd sftp winscp


    【解决方案1】:

    这似乎有效:

    setlocal enabledelayedexpansion
    set pw=!pw:+=%%2B!
    

    请注意,您必须删除 call

    基于Batch - replacing with percent symbol


    此外,还有另一种方法可以使用 -password switch 向 WinSCP 提供密码。

    open ftp://username@ftp.example.com/ -password="mypassword+"
    

    为此,您需要 WinSCP 5.19。

    【讨论】:

    • 太棒了!第一种方法完美;我会尽快尝试使用 winscp 的替代方法。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-07
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多