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

Author Message
[View user's profile]

Joined: 2015-02-05
Posts: 5
i would like to pass the hostkey through environment variable in batch scripting, like it is explained in
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

[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26515
Location: Prague, Czechia
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.
[View user's profile]

Joined: 2015-02-05
Posts: 5
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%


You can post new topics in this forum


What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License