Skip to content

Commit 021bc96

Browse files
authored
Make more robust
[ci skip]
1 parent 7bc6ca4 commit 021bc96

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

updater.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,18 @@ def progress_callback(data):
345345
print(f"\nUploaded {file} to {selected_ip}.")
346346
except ftplib.all_errors as e:
347347
print(f"FTP error: {e}")
348+
ftp = None # Mark ftp as unusable
348349

350+
# Only attempt to send BYE if ftp is connected and has a socket
349351
try:
350-
ftp.sendcmd("BYE")
351-
print(f"Disconnected from {selected_ip}.")
352-
except ftplib.all_errors as e:
353-
if str(e).strip().lower() == "timed out":
354-
# Suppress expected timeout after BYE
352+
if ftp is not None and getattr(ftp, 'sock', None) is not None:
353+
ftp.sendcmd("BYE")
355354
print(f"Disconnected from {selected_ip}.")
355+
else:
356+
print(f"No active FTP connection to disconnect from.")
357+
except (*ftplib.all_errors, AttributeError) as e:
358+
# Handle timeout or already closed connection
359+
if isinstance(e, TimeoutError) or (str(e).strip().lower() == "timed out"):
360+
print(f"Disconnected from {selected_ip} (timeout after BYE, device likely restarted).")
356361
else:
357362
print(f"FTP error after BYE: {e}")

0 commit comments

Comments
 (0)