diff --git a/smbclientng/core/CommandCompleter.py b/smbclientng/core/CommandCompleter.py index e3004d2..280020e 100644 --- a/smbclientng/core/CommandCompleter.py +++ b/smbclientng/core/CommandCompleter.py @@ -505,15 +505,26 @@ def print_help_format(self): This function displays the format of file attributes used in the smbclient-ng shell. It explains the meaning of each character in the file attribute string, such as whether a file is read-only, hidden, or a directory. """ - - print("File attributes format:\n") - print("\x1b[1mdachnrst\x1b[0m") - print("\x1b[90m│││││││└──>\x1b[0m Temporary") - print("\x1b[90m││││││└───>\x1b[0m System") - print("\x1b[90m│││││└────>\x1b[0m Read-Only") - print("\x1b[90m││││└─────>\x1b[0m Normal") - print("\x1b[90m│││└──────>\x1b[0m Hidden") - print("\x1b[90m││└───────>\x1b[0m Compressed") - print("\x1b[90m│└────────>\x1b[0m Archived") - print("\x1b[90m└─────────>\x1b[0m Directory") + if self.config.no_colors: + print("File attributes format:\n") + print("dachnrst") + print("│││││││└──> Temporary") + print("││││││└───> System") + print("│││││└────> Read-Only") + print("││││└─────> Normal") + print("│││└──────> Hidden") + print("││└───────> Compressed") + print("│└────────> Archived") + print("└─────────> Directory") + else: + print("File attributes format:\n") + print("dachnrst") + print("\x1b[90m│││││││└──>\x1b[0m Temporary") + print("\x1b[90m││││││└───>\x1b[0m System") + print("\x1b[90m│││││└────>\x1b[0m Read-Only") + print("\x1b[90m││││└─────>\x1b[0m Normal") + print("\x1b[90m│││└──────>\x1b[0m Hidden") + print("\x1b[90m││└───────>\x1b[0m Compressed") + print("\x1b[90m│└────────>\x1b[0m Archived") + print("\x1b[90m└─────────>\x1b[0m Directory") diff --git a/smbclientng/core/SMBSession.py b/smbclientng/core/SMBSession.py index 4983585..0ea1d55 100644 --- a/smbclientng/core/SMBSession.py +++ b/smbclientng/core/SMBSession.py @@ -253,15 +253,35 @@ def get_file(self, path=None, keepRemotePath=False): None """ - tmp_file_path = self.smb_cwd + ntpath.sep + path + # Parse path + path = path.replace('/', ntpath.sep) + if ntpath.sep in path: + tmp_search_path = ntpath.normpath(self.smb_cwd + ntpath.sep + ntpath.dirname(path)) + else: + tmp_search_path = ntpath.normpath(self.smb_cwd + ntpath.sep) + # Parse filename + filename = ntpath.basename(path) + + # Search for the file matches = self.smbClient.listPath( shareName=self.smb_share, - path=tmp_file_path - ) - + path=tmp_search_path + ntpath.sep + '*' + ) + + # Filter the entries + matching_entries = [] for entry in matches: + if entry.get_longname() == filename: + matching_entries.append(entry) + elif '*' in filename: + regexp = filename.replace('.', '\\.').replace('*', '.*') + if re.match(regexp, entry.get_longname()): + matching_entries.append(entry) + + for entry in matching_entries: if entry.is_directory(): - print("[>] Skipping '%s' because it is a directory." % tmp_file_path) + if self.config.debug: + print("[debug] [>] Skipping '%s' because it is a directory." % (tmp_search_path + ntpath.sep + entry.get_longname())) else: try: if ntpath.sep in path: @@ -277,7 +297,7 @@ def get_file(self, path=None, keepRemotePath=False): ) self.smbClient.getFile( shareName=self.smb_share, - pathName=tmp_file_path, + pathName=tmp_search_path + ntpath.sep + entry.get_longname(), callback=f.write ) f.close()