gpt4 book ai didi

python - Pysftp:操作超时

转载 作者:太空宇宙 更新时间:2023-11-03 20:22:42 24 4
gpt4 key购买 nike

我正在尝试使用以下脚本连接到服务器:

import pysftp

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None

srv = pysftp.Connection(host="sftp://my_ip:my_port",
username="alessandro", password="alessandro", port=2222,
cnopts=cnopts)
data = srv.listdir()
srv.close()

for i in data:
print (i)

如果我尝试使用相同的凭据通过 FileZilla 或类似的客户端进行访问,它会起作用;即使它显示以下警告,涉及主机 key 算法和指纹:

enter image description here

但是,该脚本无法正常运行并报告以下错误:

SSHException: Unable to connect to sftp://my_ip:my_port: [Errno 60] Operation timed out

即使我仅尝试使用host = my_ip。另外,如果我不设置 cnopts,它就找不到主机 key 。

如何解决?

最佳答案

Connection constructorhost 参数是:

The Hostname or IP of the remote machine.

不是URL

所以应该是:

srv = pysftp.Connection(host="my_ip", 
username="alessandro", password="alessandro", port=2222,
cnopts=cnopts)
<小时/>

此外,请勿设置cnopts.hostkeys = None,除非您不关心安全性。
正确的解决方案请参见Verify host key with pysftp

关于python - Pysftp:操作超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58053075/

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