python - 尝试使用 Python PySFTP 模块连接到远程服务器时出现 WinError 10060 错误
问题描述
我正在尝试使用以下代码连接到远程服务器并列出路径内的文件:
import pysftp
myHostname = "myhostname.com"
myPort = <someportnumber>
myUsername = "<valid username>"
myPassword = "<valid password>"
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword, cnopts= cnopts, port=myPort) as sftp:
print("Connection succesfully established ... ")
sftp.chdir('/logs/dev')
# Obtain structure of the remote directory
directory_structure = sftp.listdir_attr()
# Print data
for attr in directory_structure:
print(attr.filename, attr)
但是当我运行它时,它无法建立连接。它抛出以下异常:
Traceback (most recent call last):
File "c:/Users/611841191/Documents/SFTP File Download/SFTPFileDownload.py", line 11, in <module>
with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword, cnopts= cnopts, port=myPort) as sftp:
File "C:\Users\611841191\AppData\Roaming\Python\Python38\site-packages\pysftp\__init__.py", line 140, in __init__
self._start_transport(host, port)
File "C:\Users\611841191\AppData\Roaming\Python\Python38\site-packages\pysftp\__init__.py", line 176, in _start_transport
self._transport = paramiko.Transport((host, port))
File "C:\Users\611841191\AppData\Roaming\Python\Python38\site-packages\paramiko\transport.py", line 415, in __init__
raise SSHException(
paramiko.ssh_exception.SSHException: Unable to connect to <myhostname.com>: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond
谁能帮我解释为什么抛出这个异常,因为我尝试使用其他远程服务器并且代码似乎对他们来说工作正常?该代码仅对一个特定的远程服务器抛出异常。
解决方案
推荐阅读
- amazon-web-services - 资源策略网关 - IAM
- c++ - 在 CPP 中交换 2 个号码
- selenium - 提取 selenium-server-standalone jar 文件时询问是否替换现有文件
- java - 使用 XML 的 CORBA 消息传递——如何
- flutter - Flutter 应用在提交商店之前是否需要相机权限?
- itext7 - 如何允许第二个签名者在第一个签名者签名后放置水印?
- python - Pandas - 如何提取每行中包含的标题?
- xcode - zsh:找不到命令:pod - MACOS Catalina 10.15
- java - 如何修复这种泛型类型?
- android - DropDownPreference setOnPreferenceChangeListener 在初始化时调用自身