【发布时间】:2019-04-20 16:14:16
【问题描述】:
我收到错误,无法加载主机密钥。
你好,
我在编写用于将文件推送到 SFTP 的脚本时遇到问题。我正在使用 Windows,下面是我到目前为止的代码。实际的数据操作和命名更改工作正常 - 它在 SFTP 部分中断。我希望你们中的一位大师可以帮助新手。
import pandas as pd
import datetime
import pysftp
import sys
today = str(datetime.date.today().strftime("%m%d%y"))
report = pd.read_csv('C:\\Users\\nickkeith2\\PycharmProjects\\clt\\041719_clt_Facility_company_Inv.csv')
report.columns = report.columns.str.replace('_', ' ')
report.to_csv('C:\\Users\\nickkeith2\\PycharmProjects\\clt\\' + today + '_clt_Facility_company_Inv2.csv',
index=False)
remote_file = 'C:\\Users\\nickkeith2\\PycharmProjects\\clt\\' + today + '_clt_Facility_company_Inv2.csv'[1]
cnopts = pysftp.CnOpts()
cnopts.hostkeys.load("C:\\Users\\nickkeith2\\id_rsa.pub")
srv = pysftp.Connection(host="xx.xxx.xxx.xxx", username="sftpuser")
srv.put(remote_file)
srv.close()
print(report.columns)
我尝试了使用密钥、不使用密钥和使用密码的各种组合 - 但无论它返回错误是什么:
UserWarning: Failed to load HostKeys from C:\Users\nickkeith2\.ssh\known_hosts. You will need to explicitly load HostKeys (cnopts.hostkeys.load(filename)) or disableHostKey checking (cnopts.hostkeys = None).
warnings.warn(wmsg, UserWarning)
我试图在 Windows 中创建文件夹,它指定将密钥放在那里,但它也不允许我这样做。提前感谢您提供的任何见解。
【问题讨论】:
-
id_rsa.pub文件不是主机密钥。 -
明确地说,客户端使用主机密钥文件来确保它所连接的主机是真实的(它是一个已知公钥列表标识远程服务器,与公钥标识正在登录的用户没有任何关系)。
-
谢谢 - 回到绘图板。
-
Charles - 在线阅读后我看到尝试:cnopts = pysftp.CnOpts() cnopts.hostkeys = None - 但这给了我同样的错误,有什么建议吗?