Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement] Added 'lcp' command, fixing #9 #21

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading