File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -345,13 +345,18 @@ def progress_callback(data):
345
345
print (f"\n Uploaded { file } to { selected_ip } ." )
346
346
except ftplib .all_errors as e :
347
347
print (f"FTP error: { e } " )
348
+ ftp = None # Mark ftp as unusable
348
349
350
+ # Only attempt to send BYE if ftp is connected and has a socket
349
351
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" )
355
354
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)." )
356
361
else :
357
362
print (f"FTP error after BYE: { e } " )
You can’t perform that action at this time.
0 commit comments