如何解决SFTP 文件传输错误 - 连接到未知服务器并添加其主机密钥
我已经创建了使用 SSH 密钥传输文件的批处理,我检查了两台服务器上的公钥和私钥映射,并且工作正常。
我使用 SFTP 命令的 Windows 批处理代码如下:
open sftp://sftp_user@ssh_dest_server -privatekey="D:\directory_full_path\private_key.ppk" -rawsettings TryAgent=0 AuthKI=0 AuthGSSAPI=0
CD "/XYZ_Directory/folder1"
Put "\\full_directory_path\FILE1.zip"
exit
当我手动执行批处理时,它执行得很好,没有任何问题,但是当我从 SQL 作业(使用不同的用户)执行批处理时,它会显示以下错误:
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 RSA key details are:
Algorithm: ssh-rsa 2048
SHA-256: finger_print_key
MD5: zz:xx:yy:xx:yy:xx:yy:xx:yy:xx:yy:xx:yy:zz:zz:00
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.
(Y)es,(N)o,C(a)ncel (10 s),(C)opy Key,(P)aste key: Cancel
Host key wasn't verified!
Host key fingerprint is ssh-rsa 2048 finger_print_key.
Authentication failed.
我已经尝试过 -hostkey
WinSCP 命令,但显示“未知命令”。非常欢迎提出建议。
我想通过 WinSCP 命令执行此链接“WinSCP”,但会自动在我的 Windows 批处理中执行以验证主机。
解决方法
要验证 WinSCP 脚本中的主机密钥,请添加 -hostkey
switch to the open
command:
open sftp://sftp_user@ssh_dest_server -hostkey=... -privatekey="D:\directory_full_path\private_key.ppk" -rawsettings TryAgent=0 AuthKI=0 AuthGSSAPI=0
请参阅 WinSCP 文档中的 Verifying the host key ... in script。它涵盖了您需要了解的一切。特别是,where to get the host key value。
另请注意,即使使用 -hostkey
开关,WinSCP GUI 也可以generate a script template。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。