Make more robust

[ci skip]
pull/906/head assets
probonopd 1 week ago committed by GitHub
parent 7bc6ca4d72
commit 021bc962b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      updater.py

@ -345,13 +345,18 @@ if __name__ == "__main__":
print(f"\nUploaded {file} to {selected_ip}.") print(f"\nUploaded {file} to {selected_ip}.")
except ftplib.all_errors as e: except ftplib.all_errors as e:
print(f"FTP error: {e}") print(f"FTP error: {e}")
ftp = None # Mark ftp as unusable
# Only attempt to send BYE if ftp is connected and has a socket
try: try:
ftp.sendcmd("BYE") if ftp is not None and getattr(ftp, 'sock', None) is not None:
print(f"Disconnected from {selected_ip}.") ftp.sendcmd("BYE")
except ftplib.all_errors as e:
if str(e).strip().lower() == "timed out":
# Suppress expected timeout after BYE
print(f"Disconnected from {selected_ip}.") print(f"Disconnected from {selected_ip}.")
else:
print(f"No active FTP connection to disconnect from.")
except (*ftplib.all_errors, AttributeError) as e:
# Handle timeout or already closed connection
if isinstance(e, TimeoutError) or (str(e).strip().lower() == "timed out"):
print(f"Disconnected from {selected_ip} (timeout after BYE, device likely restarted).")
else: else:
print(f"FTP error after BYE: {e}") print(f"FTP error after BYE: {e}")

Loading…
Cancel
Save