尝试使用ssh键连接到sftp服务器
#!/bin/python
import pysftp
with pysftp.Connection(host='sftp.myserver.com', username='stg', private_key='/Users/joel/.ssh/id_rsa_sftp', private_key_pass='') as sftp:
我正在得到
raise SSHException("No hostkey for host %s found." % host)
您可以使用github中的pysftp分支并添加auto_add_key=True
这会将首次连接上的主机密钥添加到您的known_hosts
文件...
import pysftp
with pysftp.Connection('hostname', username='me', password='secret', auto_add_key=True) as sftp:
with sftp.cd('public'): # temporarily chdir to public
sftp.put('/my/local/filename') # upload file to public/ on remote
sftp.get('remote_file') # get a remote file