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] Implemented 'lrename' command, fixed #10 #17

Merged
merged 3 commits into from
Jun 4, 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
7 changes: 7 additions & 0 deletions smbclientng/core/CommandCompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ class CommandCompleter(object):
],
"subcommands": []
},
"lrename": {
"description": [
"Renames a local file.",
"Syntax: 'lrename <oldfilename> <newfilename>'"
],
"subcommands": []
},
"lrm": {
"description": [
"Removes a local file.",
Expand Down
20 changes: 17 additions & 3 deletions smbclientng/core/InteractiveShell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -629,9 +644,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:
Expand Down Expand Up @@ -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")
Expand Down
Loading