我正在尝试连接到远程服务器并使用以下代码列出路径内的文件:import pysftpmyHostname = "myhostname.com"myPort = <someportnumber>myUsername = "<valid username>"myPassword = "<valid password>"cnopts = pysftp.CnOpts()cnopts.hostkeys = Nonewith 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 任何人都可以帮助我解决为什么抛出此异常的原因,因为我尝试使用其他远程服务器并且代码似乎对他们来说工作正常?该代码仅针对一个特定的远程服务器抛出异常。
添加回答
举报
0/150
提交
取消