From f96c3d368ed96799b1d4724a0acb9a0e49798060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20GASCOU=20=28Podalirius=29?= Date: Tue, 4 Jun 2024 13:54:07 +0200 Subject: [PATCH] [enhancement] Implemented 'lrename' command, fixed #10 (#17) * Improved logic of 'shares' command to keep remotely advertised case * Improved logic of 'shares' command to keep remotely advertised case * Implemented 'lrename' command, fixed #10 --- smbclientng/core/CommandCompleter.py | 7 +++++++ smbclientng/core/InteractiveShell.py | 20 +++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/smbclientng/core/CommandCompleter.py b/smbclientng/core/CommandCompleter.py index a708b5c..ea3fafc 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 bb001ce..774ee8f 100644 --- a/smbclientng/core/InteractiveShell.py +++ b/smbclientng/core/InteractiveShell.py @@ -193,6 +193,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) @@ -451,6 +455,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 @@ -636,9 +651,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]["name"], str(is_hidden), types, shares[sharename]["comment"]) else: - table.add_row(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: @@ -676,7 +691,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")