python-3.x - 使用 pysftp 连接到服务器失败
问题描述
我正在研究 python 自动化以检查远程服务器中是否有指定的文件。这里使用的模块是 pysftp。但它因以下错误而失败。
File "invader_script_paramiko.py", line 7, in <module>
with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword) as sftp:
File "/root/python3-virtualenv/lib64/python3.6/site-packages/pysftp/__init__.py", line 132, in __init__
self._tconnect['hostkey'] = self._cnopts.get_hostkey(host)
File "/root/python3-virtualenv/lib64/python3.6/site-packages/pysftp/__init__.py", line 71, in get_hostkey
raise SSHException("No hostkey for host %s found." % host)
paramiko.ssh_exception.SSHException: No hostkey for host hvipk0000015pr.xxxdc.local found.
Exception ignored in: <bound method Connection.__del__ of <pysftp.Connection object at 0x7f111b6a8e48>>
Traceback (most recent call last):
File "/root/python3-virtualenv/lib64/python3.6/site-packages/pysftp/__init__.py", line 1013, in __del__
self.close()
File "/root/python3-virtualenv/lib64/python3.6/site-packages/pysftp/__init__.py", line 784, in close
if self._sftp_live:
AttributeError: 'Connection' object has no attribute '_sftp_live'
实施:
import pysftp
myHostname = "hvipk0000015pr.xxxdc.local"
myUsername = "xxxxx\\username_sa"
myPassword = "password"
with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword) as sftp:
print("Connection succesfully stablished ... ")
# Switch to a remote directory
sftp.cwd('/srv/data/xxx_bperf_knnfs_pr/Check_transit/Dummy')
# Obtain structure of the remote directory '/var/www/vhosts'
directory_structure = sftp.listdir_attr()
# Print data
for attr in directory_structure:
print(attr.filename, attr)
# connection closed automatically at the end of the with-block
如果有人能够识别我的代码片段中缺少的内容以进行成功连接,将不胜感激。提前致谢
解决方案
推荐阅读
- c# - 逗号分隔、竖线分隔记录的排序列表
- javascript - UnhandledPromiseRejectionWarning:TypeError:message.author.displayAvatarURL 不是函数
- python - 结合 2 个 numpy 数组
- singly-linked-list - 为什么我得到无限循环
- python - SciPy Linprog() 优化
- c++ - 如何捕获由 boost::spirit::x3 解析器解析的值,以在语义动作的主体中使用?
- python - FLASK,Heroku,React CORS 问题
- node.js - 连接节点和 mongo 时出错,因为无法 GET /
- ruby - 如何将我的两种方法组合成一种方法?
- c# - 不能使用光流功能