Passing hostkey (sftp) as environment variable is not possible in batch scripting

Advertisement

mwweb15
Joined:
Posts:
5

Passing hostkey (sftp) as environment variable is not possible in batch scripting

Hello
i would like to pass the hostkey through environment variable in batch scripting, like it is explained in
https://winscp.net/eng/docs/guide_protecting_credentials_for_automation
for passing the user/password-credentials ("Using WinSCP scripting")

The following line in example script (example.txt) does not work

open sFtp://%PAR_1%:%PAR_2%@IP:Port/ -hostkey=%PAR_3%

open sFtp://%PAR_1%:%PAR_2%@IP:Port/ -hostkey="%PAR_3%" does not work either

The credentials and the hostkey are set as environment-variables (PAR_1, PAR_2, PAR_3) before the script is executed.
It seems that the environment variable for the hostkey is not resolved but the user and password variables are resolved.
Does anybody no if there is a way to pass the hostkey?
The Version of Winscp.exe is 5.7.4.5553

Thanks

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: Passing hostkey (sftp) as environment variable is not possible in batch scripting

The environment variables are resolved even before the command is parsed. So there cannot be a difference when using environment variable for host key and username.
You indeed have to enclose the hostkey to double-quotes, as the fingerprint usually contains spaces.

Please attach a full log file showing the problem (using the latest version of WinSCP).

To generate log file, use /log=path_to_log_file command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Also show us your batch file.

Reply with quote

mwweb15
Joined:
Posts:
5

Re: Passing hostkey (sftp) as environment variable is not possible in batch scripting

Answer (SOLVED)
Thanks for your hints. I found the problem, sorry it was my fault.
The environment variable %PAR_3% was not set correctly in the batchfile, sorry.

The following command in the script works perfect, the hostkey is resolved correctly
open sFtp://%PAR_1%:%PAR_2%@IP:Port/ -hostkey=%PAR_3%

Regards

Reply with quote

Advertisement

You can post new topics in this forum