无法连接到 {}: {}".format(主机名、原因)



我有我的下面,这是工作良好的几天回来,突然现在它停止工作。当我运行文件时,我得到以下错误。

Traceback (most recent call last):
File "/app/www/html/project/connect.py", line 8, in <module>
transport = paramiko.Transport((host, port))
File "/usr/local/lib/python3.6/site-packages/paramiko/transport.py", line 416, in __init__
"Unable to connect to {}: {}".format(hostname, reason)
paramiko.ssh_exception.SSHException: Unable to connect to mft.schneider-electric.com: [Errno 110] Connection timed out

这是我的代码。

import paramiko
import os
paramiko.util.log_to_file('logfile.log')
host = "ftp.myserver.com"
port = 22
transport = paramiko.Transport((host, port))
password = "mypassword"
username = "myusername"
folder = "/Home/foldername/Automation_DKC_"
transport.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(transport)
print("Successfully Connected to SFTP")
latest = 0
latestfile = None
for fileattr in sftp.listdir_attr():
if fileattr.filename.startswith('Automation_DKC') and fileattr.st_mtime > latest:
latest = fileattr.st_mtime
latestfile = fileattr.filename

filepath = '/Home/foldername/' +latestfile
localpath = '/app/www/html/project/dkc.csv'
sftp.get(filepath, localpath)
sftp.close()
transport.close()
请在这件事上帮助我。谢谢你。

程序工作正常,它实际上是服务器防火墙问题,无法连接。我的IT团队解决了这个问题。

相关内容

最新更新