WinError 10060尝试使用Python PySFTP模块连接到远程服务器时出错

乌曼巴蒂亚

我正在尝试连接到远程服务器,并使用以下代码列出路径内的文件:

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 

有人可以帮我解决为什么因为我尝试过其他远程服务器而抛出此异常的原因,而这些代码对于它们来说似乎工作正常?该代码仅对一台特定的远程服务器抛出异常。

马丁·普里克里(Martin Prikryl)

如果您的代码无法使用某些协议(在本例中为SFTP)连接到某处,则要测试的第一件事是,是否可以使用运行代码的同一台计算机上的任何现有GUI /命令行客户端使用同一协议进行连接。

如果这也不起作用,则您不会遇到编程问题,而是一个简单的网络连接问题。

如果您需要解决问题的帮助,请转到“超级用户服务器故障”

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

尝试连接到服务器时,Sshutle连接被拒绝

尝试从Gitea连接到AD服务器时出错

远程连接到简单的套接字python服务器

使用私钥连接到服务器时,pysftp AuthenticationException

使用Ionic连接到MongoDB远程服务器

PermissionError:尝试删除临时图像时出现[WinError 32]

Python 3-安装新模块时出现WinError 87

尝试将Pyftpsync连接到端口22上的远程服务器时出现EFOError

使用pysftp连接到SFTP服务器时出现“无法加载HostKeys”警告

使用python连接到远程服务器,添加代理

TimeoutError:[WinError 10060]:

WinError 17,WinError 12和其他尝试重命名文件时

无法使用XMPPFramework连接到远程服务器

我尝试连接到服务器时出现“远程服务器超时”异常

使用JDBC连接到远程MySQL(主机gator)服务器时出错

使用JSP在tomcat服务器中连接到Oracle数据库时出错

连接到Python HTTP服务器时出错

使用IDE连接到Openshift服务器时出错

使用HttpURLConnection连接到远程服务器

使用JAVA通过FTP连接到远程服务器

使用C#和.NET 4.5连接到SSL服务器时出错

尝试连接到蓝牙服务器时连接被拒绝

使用 letencrypt ssl 连接到远程 RabbitMQ 服务器

Android - 尝试连接到本地服务器时出错(Xampp)

无法连接到本地 pyftpdlib FTP 服务器:[WinError 10061] 无法建立连接

带有代理的 Python 请求因 WinError 10060 失败

错误:无法连接到服务器 127.0.0.1:27017,连接尝试失败:SocketException:连接到 127.0.0.1:27 时出错

AWS Python 套接字客户端超时错误:[WinError 10060] 连接尝试失败

无法使用 Swift 连接到远程 RabbitMQ 服务器