首页 > 解决方案 > 尽管已将 -hostkey 开关添加到 WinSCP 命令行,但“主机密钥未验证”

问题描述

我正在尝试使用具有以下命令行参数的 SSIS 执行进程任务建立 SFTP 连接。

/log=G:\USER_DATA\USER_USER_SYNC\SFTP_LOG\user_sync_winscp.log /command "open sftp://username:password@stransfer.host.com/" "get /DATA/UserRoleUpdate.csv G:\USER_DATA\USER_USER_SYNC\Download\" "exit"

给定的执行进程任务使用 WinSCP exe 将文件下载到本地驱动器。包在调试模式下成功运行,当我通过 SQL 服务器上的 SSISDB 文件夹手动运行时也是如此。

我们在尝试使用作业代理执行 SSIS 包时遇到问题。如果我禁用使 SFTP 连接的特定任务,那么包也可以通过作业代理成功运行。似乎只有该特定任务有问题。我很难理解为什么会发生这种情况以及需要做些什么来解决这个问题。

当我检查user_sync_winscp.log文件时,我发现了这个。

. 2019-08-20 08:10:23.931 Host key fingerprint is:
. 2019-08-20 08:10:23.931 ssh-rsa 2048 9b:63:5e:c4:26:bb:35:0d:49:e6:74:5e:5a:48:c0:8a bLgYggTcP4U6A/IFkFoyfY8BhlCB/+i5fFhzq1z1MjQ=
. 2019-08-20 08:10:23.931 Asking user:
. 2019-08-20 08:10:23.931 **Continue connecting to an unknown server and add its host key to a cache?** . 2019-08-20 08:10:23.931 . 2019-08-20 08:10:23.931 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.
. 2019-08-20 08:10:23.931
. 2019-08-20 08:10:23.931 The server's RSA key details are:
. 2019-08-20 08:10:23.931 
. 2019-08-20 08:10:23.931     Algorithm:    ssh-rsa 2048
. 2019-08-20 08:10:23.931     SHA-256:  bLgYggTcP4U6A/IFkFoyfY8BhlCB/+i5fFhzq1z1MjQ=
. 2019-08-20 08:10:23.931     MD5:  9b:63:5e:c4:26:bb:35:0d:49:e6:74:5e:5a:48:c0:8a
. 2019-08-20 08:10:23.931
. 2019-08-20 08:10:23.931 If you trust this host, press Yes. To connect without adding host key to the cache, press No. To abandon the connection press Cancel.
. 2019-08-20 08:10:23.931 In scripting, you should use a -hostkey switch to configure the expected host key. () . 2019-08-20 08:10:33.933 Attempt to close connection due to fatal exception:
* 2019-08-20 08:10:33.933 Host key fingerprint is ssh-rsa 2048 bLgYggTcP4U6A/IFkFoyfY8BhlCB/+i5fFhzq1z1MjQ=.
* 2019-08-20 08:10:33.933 (Exception) **Host key wasn't verified!** . 2019-08-20 08:10:33.933 Closing connection.
. 2019-08-20 08:10:33.933 Sending special code: 12

然后,我从日志文件中复制了主机密钥,并通过添加-hostkey="..."如下所示的开关来更改我的命令行参数。

/log=G:\USER_DATA\USER_USER_SYNC\SFTP_LOG\user_sync_winscp.log /command "open sftp://username:password@stransfer.host.com/" -hostkey="ssh-rsa 2048 9b:63:5e:c4:26:bb:35:0d:49:e6:74:5e:5a:48:c0:8a" "get /DATA/UserRoleUpdate.csv G:\USER_DATA\USER_USER_SYNC\Download\" "exit"

现在任务在本地失败。

如果我需要添加更多关于此的详细信息,请告诉我。谢谢

标签: ssissftpwinscp

解决方案


正确的语法是:

... /command "open sftp://username:password@stransfer.host.com/ -hostkey=""ssh-rsa 2048 9b:63:5e:c4:26:bb:35:0d:49:e6:74:5e:5a:48:c0:8a""" "get ..." ...

请参阅 WinSCP命令行语法open命令语法


WinSCP GUI 可以为您生成正确的脚本/命令行,包括-hostkeyswitch


推荐阅读