在批处理脚本中管理特殊字符以写入WinSCP“打开”连接字符串

问题描述 投票:1回答:1

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

open sftp://user:[email protected]/

密码包含+符号,为了使WinSCP能够理解,我必须将其更改为%2B

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个回答
0
投票

这似乎起作用:

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

注意,您必须删除call

基于Batch - replacing with percent symbol


此外,还有另一种向WinSCP提供密码的方法:

open ftp://[email protected]/ -rawsettings PasswordPlain="mypassword+"
© www.soinside.com 2019 - 2024. All rights reserved.