Skip to content

Commit

Permalink
Added 'lcp' command, fixing #9 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
p0dalirius authored Jun 7, 2024
1 parent 0f5dd34 commit 8136239
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
9 changes: 8 additions & 1 deletion smbclientng/core/CommandCompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ class CommandCompleter(object):
],
"subcommands": []
},
"lcp": {
"description": [
"Create a copy of a local file.",
"Syntax: 'lcp <srcfile> <dstfile>'"
],
"subcommands": []
},
"lls": {
"description": [
"Lists the contents of the current local directory.",
Expand Down Expand Up @@ -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():
Expand Down
23 changes: 23 additions & 0 deletions smbclientng/core/InteractiveShell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8136239

Please sign in to comment.