我正在嘗試連接到遠程服務器并使用以下代碼列出路徑內的文件: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
提交
取消