PowerShell having issues with placing the hostkey in the correct position
When I run my PowerShell with the code below:
PowerShell ISE shows this in the output window
It produces a string like this:
But then I get "Searching for host.... Network error timed out" from the WinSCP Log. It is obvious that I am putting the hostkey into the string wrong. I followed examples I found. I can't figure out what I'm doing wrong.
$cmdline += " `"open $ftpsite " $cmdline += " -privatekey=$privatekey " $cmdline += " -rawsettings ProxyMethod=3 ProxyHost=XX.xxx.xxx.xx ProxyPort=8080`" " $cmdline += " `"lcd $OutboundDir`" " $cmdline += " `"cd $ftpdirectory`" " $cmdline += " `"put $filter`" " $cmdline += " `"exit`" >>$FullPathToLogFile"
So I added the fingerprint above to my Hostkey parameter as below:Continue connecting to an unknown server and add its host key to a cache?
The server's host key was not found in the cache. You have no guarantee that the server is the computer you think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
$cmdline += " `"open $ftpsite " $cmdline += " -hostkey=`"ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx`" " $cmdline += " -privatekey=$privatekey " $cmdline += " -rawsettings ProxyMethod=3 ProxyHost=XX.xxx.xxx.xx ProxyPort=8080`" " $cmdline += " `"lcd $OutboundDir`" " $cmdline += " `"cd $ftpdirectory`" " $cmdline += " `"put $filter`" " $cmdline += " `"exit`" >>$FullPathToLogFile"
& "Z:\WinSCP-5.9.2-Portable\winscp.com" /command "option batch abort" "option confirm off" "open sftp://userid@FTP.xyz.com:2222/ -hostkey="ssh-rsa 2048 ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" -privatekey=Z:\xyz\Private_Key.PPK -rawsettings ProxyMethod=3 ProxyHost=xx.xxx.xxx.xx ProxyPort=8080" "lcd Z:\outbound\SAP" "cd /i501000PV/i501000_Structure_TEST/Upload" "put *.csv" "exit" >>Z:\temp\winscp.log