From 7d0bc313efd9465babc76ab53d62d00c0e3d5020 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:44:15 +0200 Subject: [PATCH 1/3] Improved logic of 'shares' command to keep remotely advertised case --- smbclientng/core/InteractiveShell.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smbclientng/core/InteractiveShell.py b/smbclientng/core/InteractiveShell.py index 61cf86c..e957062 100644 --- a/smbclientng/core/InteractiveShell.py +++ b/smbclientng/core/InteractiveShell.py @@ -629,9 +629,9 @@ def command_shares(self, arguments, command): is_hidden = bool(sharename.endswith('$')) types = ', '.join([s.replace("STYPE_","") for s in shares[sharename]["type"]]) if is_hidden: - table.add_row(sharename, str(is_hidden), types, shares[sharename]["comment"]) + table.add_row(shares[sharename], str(is_hidden), types, shares[sharename]["comment"]) else: - table.add_row(sharename, str(is_hidden), types, shares[sharename]["comment"]) + table.add_row(shares[sharename], str(is_hidden), types, shares[sharename]["comment"]) Console().print(table) else: From a14eff97c91720f0ac6b4ebdd7cb3121226224f3 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:45:02 +0200 Subject: [PATCH 2/3] Improved logic of 'shares' command to keep remotely advertised case --- smbclientng/core/InteractiveShell.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smbclientng/core/InteractiveShell.py b/smbclientng/core/InteractiveShell.py index e957062..c6c932a 100644 --- a/smbclientng/core/InteractiveShell.py +++ b/smbclientng/core/InteractiveShell.py @@ -629,9 +629,9 @@ def command_shares(self, arguments, command): is_hidden = bool(sharename.endswith('$')) types = ', '.join([s.replace("STYPE_","") for s in shares[sharename]["type"]]) if is_hidden: - table.add_row(shares[sharename], str(is_hidden), types, shares[sharename]["comment"]) + table.add_row(shares[sharename]["name"], str(is_hidden), types, shares[sharename]["comment"]) else: - table.add_row(shares[sharename], str(is_hidden), types, shares[sharename]["comment"]) + table.add_row(shares[sharename]["name"], str(is_hidden), types, shares[sharename]["comment"]) Console().print(table) else: From d00c148286c48212cd6714807b1bad927e7101ca Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:51:26 +0200 Subject: [PATCH 3/3] Implemented 'lrename' command, fixed #10 --- smbclientng/core/CommandCompleter.py | 7 +++++++ smbclientng/core/InteractiveShell.py | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/smbclientng/core/CommandCompleter.py b/smbclientng/core/CommandCompleter.py index a08e68a..ed4a7ec 100644 --- a/smbclientng/core/CommandCompleter.py +++ b/smbclientng/core/CommandCompleter.py @@ -124,6 +124,13 @@ class CommandCompleter(object): ], "subcommands": [] }, + "lrename": { + "description": [ + "Renames a local file.", + "Syntax: 'lrename '" + ], + "subcommands": [] + }, "lrm": { "description": [ "Removes a local file.", diff --git a/smbclientng/core/InteractiveShell.py b/smbclientng/core/InteractiveShell.py index c6c932a..fef8a26 100644 --- a/smbclientng/core/InteractiveShell.py +++ b/smbclientng/core/InteractiveShell.py @@ -186,6 +186,10 @@ def process_command(self, command, arguments=[]): elif command == "lpwd": self.command_lpwd(arguments, command) + # Renames a local file + elif command == "lrename": + self.command_lrename(arguments, command) + # Removes a local file elif command == "lrm": self.command_lrm(arguments, command) @@ -444,6 +448,17 @@ def command_lpwd(self, arguments, command): print(os.getcwd()) + @command_arguments_required + def command_lrename(self, arguments, command): + # Command arguments required : Yes + # Active SMB connection needed : No + # SMB share needed : No + + if len(arguments) == 2: + os.rename(src=arguments[0], dst=arguments[1]) + else: + self.commandCompleterObject.print_help(command=command) + @command_arguments_required def command_lrm(self, arguments, command): # Command arguments required : Yes @@ -669,7 +684,6 @@ def command_use(self, arguments, command): def __load_modules(self): - self.modules.clear() modules_dir = os.path.normpath(os.path.dirname(__file__) + os.path.sep + ".." + os.path.sep + "modules")