I will look at the .NETlink. These are old PS scripts and I need to get this to work without rewriting it. The
-hostkey
parameter itself is giving me problems (even after I made the suggested change). If I don't use the
-hostkey
parameter, I can connect to the FTP server.
$cmdline += " `"open $ftpsite "
#$cmdline += " -hostkey=`"`"ssh-rsa 2048 03:00:4f:c6:65:0a:90:0e:d5:fc:56:05:a4:fe:0c:d5`"`" "
$cmdline += " -privatekey=$privatekey "
$cmdline += " -rawsettings ProxyMethod=3 ProxyHost=xx.xxx.xxx.xx ProxyPort=8080`" "
#$cmdline += " -hostkey=`"`"ssh-rsa 2048 03:00:4f:c6:65:0a:90:0e:d5:fc:56:05:a4:fe:0c:d5`"`" "
$cmdline += " `"lcd $OutboundDir`" "
$cmdline += " `"cd $ftpdirectory`" "
$cmdline += " `"put $filter`" "
$cmdline += " `"exit`" >>$FullPathToLogFile"
output from my logging - it gets to the server because it says
"Authenticating":
3/30/2023 7:50:27 AM - Starting FTP Process on Directory: Z:\Applications\PVToOracle\Outbound\SAP
& "Z:\Applications\WinSCP-5.9.2-Portable\winscp.com" /command "option batch abort" "option confirm off" "open sftp://xxxxxxx@xxxx.xxx.com:2222/ -privatekey=Z:\Applications\WinSCP-5.9.2-Portable\Private_Key.PPK -rawsettings ProxyMethod=3 ProxyHost=xx.xxx.xxx.xxx ProxyPort=8080" "lcd Z:\Applications\PVToOracle\Outbound\SAP" "cd /i501000PV/i501000_Structure_TEST/Upload" "put *.csv" "exit" >>Z:\Applications\PVToOracle\Log\SAP\SAP-2023-03-30--07-50.log
batch abort
reconnecttime 120
confirm off
Searching for host...
Connecting to host...
Authenticating...
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 03:00:4f:c6:65:0a:90:0e:d5:fc:56:05:a4:fe:0c:d5
If you trust this host, press Yes. To connect without adding host key to the cache, press No. To abandon the connection press Cancel.
In scripting, you should use a -hostkey switch to configure the expected host key.
If I use this code and put
-hostkey
right after the "Site" which is where I see a lot of examples put it - it never gets to
"Authenticating":
$cmdline += " `"open $ftpsite "
$cmdline += " -hostkey=`"`"ssh-rsa 2048 03:00:4f:c6:65:0a:90:0e:d5:fc:56:05:a4:fe:0c:d5`"`" "
$cmdline += " -privatekey=$privatekey "
$cmdline += " -rawsettings ProxyMethod=3 ProxyHost=xx.xxx.xxx.xx ProxyPort=8080`" "
#$cmdline += " -hostkey=`"`"ssh-rsa 2048 03:00:4f:c6:65:0a:90:0e:d5:fc:56:05:a4:fe:0c:d5`"`" "
$cmdline += " `"lcd $OutboundDir`" "
$cmdline += " `"cd $ftpdirectory`" "
$cmdline += " `"put $filter`" "
$cmdline += " `"exit`" >>$FullPathToLogFile"
The output is this - it never uses the proxy settings to
3/30/2023 7:59:14 AM - Starting FTP Process on Directory: Z:\Applications\PVToOracle\Outbound\SAP
& "Z:\Applications\WinSCP-5.9.2-Portable\winscp.com" /command "option batch abort" "option confirm off" "open sftp://xxxxx@xxx.xx.com:2222/ -hostkey=""ssh-rsa 2048 03:00:4f:c6:65:0a:90:0e:d5:fc:56:05:a4:fe:0c:d5"" -privatekey=Z:\Applications\WinSCP-5.9.2-Portable\Private_Key.PPK -rawsettings ProxyMethod=3 ProxyHost=xx.xx.xx.xx ProxyPort=8080" "lcd Z:\Applications\PVToOracle\Outbound\SAP" "cd /i501000PV/i501000_Structure_TEST/Upload" "put *.csv" "exit" >>Z:\Applications\PVToOracle\Log\SAP\SAP-2023-03-30--07-59.log
batch abort
reconnecttime 120
confirm off
Searching for host...
If I move
-hostkey
out of the
open
command to this spot - then it gets to
"Authenticating" but the figerprint is not "noticed":
$cmdline += " `"open $ftpsite "
#$cmdline += " -hostkey=`"`"ssh-rsa 2048 03:00:4f:c6:65:0a:90:0e:d5:fc:56:05:a4:fe:0c:d5`"`" "
$cmdline += " -privatekey=$privatekey "
$cmdline += " -rawsettings ProxyMethod=3 ProxyHost=xx.xx.xx.xx ProxyPort=8080`" "
$cmdline += " -hostkey=`"`"ssh-rsa 2048 03:00:4f:c6:65:0a:90:0e:d5:fc:56:05:a4:fe:0c:d5`"`" "
$cmdline += " `"lcd $OutboundDir`" "
$cmdline += " `"cd $ftpdirectory`" "
$cmdline += " `"put $filter`" "
$cmdline += " `"exit`" >>$FullPathToLogFile"
The output is this - it first has problems connecting, but then seems to find the proxy and starts authenticating
3/30/2023 8:04:11 AM - Starting FTP Process on Directory: Z:\Applications\PVToOracle\Outbound\SAP
& "Z:\Applications\WinSCP-5.9.2-Portable\winscp.com" /command "option batch abort" "option confirm off" "open sftp://xxxx@xxx.xxx.com:2222/ -privatekey=Z:\Applications\WinSCP-5.9.2-Portable\Private_Key.PPK -rawsettings ProxyMethod=3 ProxyHost=xx.xx.xx.xx ProxyPort=8080" -hostkey=""ssh-rsa 2048 03:00:4f:c6:65:0a:90:0e:d5:fc:56:05:a4:fe:0c:d5"" "lcd Z:\Applications\PVToOracle\Outbound\SAP" "cd /i501000PV/i501000_Structure_TEST/Upload" "put *.csv" "exit" >>Z:\Applications\PVToOracle\Log\SAP\SAP-2023-03-30--08-04.log
Scripting does not use standalone parameters. The parameters you have specified on command-line will not be used. Your command-line syntax is probably wrong.
Opening session using command-line parameter in scripting is deprecated. Use 'open' command instead.
Searching for host...
Network error: Network is unreachable
batch abort
reconnecttime 120
confirm off
Searching for host...
Connecting to host...
Authenticating...
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 03:00:4f:c6:65:0a:90:0e:d5:fc:56:05:a4:fe:0c:d5
If you trust this host, press Yes. To connect without adding host key to the cache, press No. To abandon the connection press Cancel.
In scripting, you should use a -hostkey switch to configure the expected host key.