Without timeout, it seeems like ftp might be stuck forever under certain network condition.
import socketfrom ftplib import FTP, error_tempfrom time import sleepHOST = ...USERNAME = ...PASSWORD = ...ftp = FTP(HOST, timeout=60*5)ftp.login(USERNAME, PASSWORD)local_path = ...remote_path = ...# download filewhile True: try: with open(local_path, 'wb') as file : ftp.retrbinary(f"RETR {remote_path}", file.write) break except (error_temp, BrokenPipeError, socket.timeout) as e: try_count += 1 if try_count > 3: raise e else: print(e) sleep(try_count * 2)