gpt4 book ai didi

python - 如何创建一个已知的主机文件?

转载 作者:行者123 更新时间:2023-12-05 06:55:45 26 4
gpt4 key购买 nike

<分区>

我正在尝试使用 python 连接到 SFTP 站点,但我的 Windows 10 计算机上不存在 known_hosts 文件。网上查到第一次连接服务器时出现host key:https://winscp.net/eng/docs/ssh_verifying_the_host_key

如何将其转换为可在我的 python 代码中使用的 known_hosts 文件?

在上面的示例中,我尝试创建一个类似于 hostname ssh-rsa 2EP...8MZ 的文件,但我收到一个无效的主机 key 错误:Error('Incorrect padding'))

谢谢。

import pysftp

cnopts = pysftp.CnOpts(knownhosts='C:\\Users\\Documents\\known_hosts')

with pysftp.Connection('xxx',username='xxx', password='xxx',cnopts=cnopts) as sftp:
localpath='TEST.txt'
remotepath='TEST.txt'
sftp.put(localpath,remotepath)
sftp.close()

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com