From: Alexander Vasarab Date: Sat, 22 Mar 2025 16:51:29 +0000 (-0700) Subject: Add a timeout to the FTP operation X-Git-Tag: v3.4.5~1 X-Git-Url: https://wylark.com/src/infoex-autowx.git/commitdiff_plain/443f57c1e43471c04e3555c797c570205c23a030 Add a timeout to the FTP operation --- diff --git a/infoex-autowx.py b/infoex-autowx.py index 8cab0c3..2cfd46e 100755 --- a/infoex-autowx.py +++ b/infoex-autowx.py @@ -27,6 +27,7 @@ import csv import datetime import logging import os +import socket import sys import time import urllib3 @@ -384,7 +385,10 @@ def main(): return 1 if not options.dry_run: - upload_csv(infoex['csv_filename'], infoex) + try: + upload_csv(infoex['csv_filename'], infoex) + except socket.timeout: + LOG.critical("FTP timed out") LOG.debug('DONE') return 0 @@ -852,7 +856,7 @@ def upload_csv(path_to_file, infoex_data): with open(path_to_file, 'rb') as file_object: LOG.debug("uploading FTP file '%s'", infoex_data['host']) ftp = FTP(infoex_data['host'], infoex_data['uuid'], - infoex_data['api_key']) + infoex_data['api_key'], timeout=10) ftp.storlines('STOR ' + path_to_file, file_object) ftp.close() file_object.close()