我正在使用 Python 2.7 pysftp 包连接到 SFTP 服务器。
import pysftp
DOWNLOAD = {
"USERNAME": "username",
"PASSWORD": "password"
}
FTP_SITE = 'sftp.mysite.com'
srv = pysftp.Connection(host=FTP_SITE, username=DOWNLOAD['USERNAME'],
password=DOWNLOAD['PASSWORD']
当我运行上面的代码时,我得到了错误日志:
---------------------------------------------------------------------------
SSHException Traceback (most recent call last)
<ipython-input-47-205bb7b4b59b> in <module>()
5
6 srv = pysftp.Connection(host=FTP_SITE, username=DOWNLOAD['USERNAME'],
----> 7 password=DOWNLOAD['PASSWORD'])
C:\Users\Alex\Anaconda2\lib\site-packages\pysftp\__init__.pyc in __init__(self, host, username, private_key, password, port, private_key_pass, ciphers, log, cnopts, default_path)
130 # check that we have a hostkey to verify
131 if self._cnopts.hostkeys is not None:
--> 132 self._tconnect['hostkey'] = self._cnopts.get_hostkey(host)
133
134 self._sftp_live = False
C:\Users\Alex\Anaconda2\lib\site-packages\pysftp\__init__.pyc in get_hostkey(self, host)
69 kval = self.hostkeys.lookup(host) # None|{keytype: PKey}
70 if kval is None:
---> 71 raise SSHException("No hostkey for host %s found." % host)
72 # return the pkey from the dict
73 return list(kval.values())[0]
SSHException: No hostkey for host sftp.mysite.com found.
我目前通过执行以下操作来关闭对主机密钥的检查:
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
srv = pysftp.Connection(host=FTP_SITE, username=DOWNLOAD['USERNAME'],
password=DOWNLOAD['PASSWORD'], cnopts=cnopts)
我想保留主机密钥的安全功能。任何人都可以提供有关如何生成主机密钥的链接,或在此处提供一小段代码示例吗?我找不到太多东西。