Py remote PC [whose login password cannot be changed] has few special characters, notably the percent sign (%
). So WinSCP script that i have written is unable to log in.
As per this document, I tried to the following, but I couldn't get any success.
My password is admin%^&
. I followed the above document and modified the password like this admin%25^&
.
How do I escape special character for WinSCP to log in?
C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\!Y!M!D_Log.log" /ini=nul ^
/command ^
"open sftp://admin:admin%25^&@137.55.111.1" ^
"put *.* %REMOTE_PATH%" ^
"exit"
The ^
and &
do not really need to be encoded (while it does not do any harm). The %
does, what you correctly did as %25
. It would work, if specified on WinSCP command-line directly. The actual problem is that the %
has a special meaning also in a batch file, not only in WinSCP. %2
is replaced by the second parameter of the batch file, even before WinSCP is started. If no (second) parameter is provided to the batch file, WinSCP sees admin5^&
(%2
is gone).
If you want to use %
literally in a batch file, you need to double it: admin%%25^&
.
Easy way is to have WinSCP GUI generate a batch file for you (note that it will [unnecessarily] encode even ^
and &
).
This is covered in WinSCP FAQ Why are some WinSCP scripting commands specified in a batch file not executed/failing?