diff --git a/smbclientng/core/SMBSession.py b/smbclientng/core/SMBSession.py index 9928d61..5a03421 100644 --- a/smbclientng/core/SMBSession.py +++ b/smbclientng/core/SMBSession.py @@ -866,12 +866,15 @@ def put_file(self, localpath=None): callback=f.read ) f.close() + except (BrokenPipeError, KeyboardInterrupt) as err: print("[!] Interrupted.") self.close_smb_session() self.init_smb_session() - except Exception as err: - print("[!] Failed to upload '%s': %s" % (localfile, err)) + + except (Exception, PermissionError) as err: + f.set_error(message="[bold red]Failed uploading '%s': %s" % (f.path, err)) + f.close(remove=False) if self.config.debug: traceback.print_exc() else: @@ -926,13 +929,16 @@ def put_file_recursively(self, localpath=None): ) f.close() - except (BrokenPipeError, PermissionError) as err: + except (BrokenPipeError, KeyboardInterrupt) as err: + print("[!] Interrupted.") + self.close_smb_session() + self.init_smb_session() + + except (Exception, PermissionError) as err: f.set_error(message="[bold red]Failed uploading '%s': %s" % (f.path, err)) - f.close(remove=True) - break - except Exception as err: - f.set_error(message="[bold red]Failed uploading '%s': %s" % (f.path, err)) - f.close(remove=True) + f.close(remove=False) + if self.config.debug: + traceback.print_exc() else: print("[!] The specified localpath is a file. Use 'put ' instead.") else: