问题
I am learning to retrieve files from an ftp server using ftplib from this link : https://docs.python.org/2/library/ftplib.html
When i run this code
from ftplib import FTP
ftp = FTP('ftp.debian.org')
ftp.login()
I get
TimeoutError: [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
From this answer https://stackoverflow.com/questions/4946960/when-using-ftplib-in-python#= i get to know that this is a server side issue which can be fixed by changing to ACTV mode.
So i changed my code to
from ftplib import FTP
ftp = FTP()
ftp.set_pasv(True)
ftp.connect('ftp.debian.org')
ftp.login()
Still same error. Can anyone tell me what other reasons could there be from my problem?
Edit - Using Python 3.6.1 on Thonny(IDE) in a 64 bit Win 10 environment
回答1:
Nothing wrong with this code. It works for me. Maybe the server was just very slow at the time you tried it. You can set a timeout in the connect:
ftp.connect('ftp.debian.org',timeout=seconds)
来源:https://stackoverflow.com/questions/44106200/python-ftplib-winerror-10060