From 6950ffaedf767f37419eeec6ddc430b36358adc8 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Fri, 7 Jun 2024 20:46:44 +0200 Subject: [PATCH] Added 'lcp' command, fixing #9 --- smbclientng/core/CommandCompleter.py | 9 ++++++++- smbclientng/core/InteractiveShell.py | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/smbclientng/core/CommandCompleter.py b/smbclientng/core/CommandCompleter.py index a2e902e..ece0766 100644 --- a/smbclientng/core/CommandCompleter.py +++ b/smbclientng/core/CommandCompleter.py @@ -110,6 +110,13 @@ class CommandCompleter(object): ], "subcommands": [] }, + "lcp": { + "description": [ + "Create a copy of a local file.", + "Syntax: 'lcp '" + ], + "subcommands": [] + }, "lls": { "description": [ "Lists the contents of the current local directory.", @@ -342,7 +349,7 @@ def complete(self, text, state): if s.lower().startswith(remainder.lower()) ] - elif command in ["lcd", "lls", "put", "lmkdir", "lrm", "lrmdir"]: + elif command in ["lcd", "lcp", "lls", "lrm", "put", "lmkdir", "lrm", "lrmdir"]: # Choose directory path = "" if os.path.sep in remainder.strip(): diff --git a/smbclientng/core/InteractiveShell.py b/smbclientng/core/InteractiveShell.py index 6ca4161..91fd4ae 100644 --- a/smbclientng/core/InteractiveShell.py +++ b/smbclientng/core/InteractiveShell.py @@ -178,6 +178,10 @@ def process_command(self, command, arguments=[]): elif command == "lcd": self.command_lcd(arguments, command) + # Creates a copy of a local file + elif command == "lcp": + self.command_lcp(arguments, command) + # Lists the contents of the current local directory elif command == "lls": self.command_lls(arguments, command) @@ -394,6 +398,25 @@ def command_lcd(self, arguments, command): else: print("[!] Directory '%s' does not exists." % path) + @command_arguments_required + def command_lcp(self, arguments, command): + # Command arguments required : Yes + # Active SMB connection needed : No + # SMB share needed : No + + if len(arguments) == 2: + src_path = arguments[0] + dst_path = arguments[1] + if os.path.exists(path=src_path): + try: + shutil.copyfile(src=src_path, dst=dst_path) + except shutil.SameFileError as err: + print("[!] Error: %s" % err) + else: + print("[!] File '%s' does not exists." % src_path) + else: + self.commandCompleterObject.print_help(command=command) + def command_lls(self, arguments, command): # Command arguments required : No # Active SMB connection needed : No