From 443f57c1e43471c04e3555c797c570205c23a030 Mon Sep 17 00:00:00 2001 From: Alexander Vasarab Date: Sat, 22 Mar 2025 09:51:29 -0700 Subject: [PATCH] Add a timeout to the FTP operation --- infoex-autowx.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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() -- 2.30.2