Skip to content

Commit

Permalink
Created get_entry() function
Browse files Browse the repository at this point in the history
  • Loading branch information
p0dalirius committed Jun 5, 2024
1 parent 3dc22e9 commit 30dbbbb
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions smbclientng/core/SMBSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def find(self, paths=[], callback=None):
def recurse_action(paths=[], depth=0, callback=None):
if callback is None:
return []

next_directories_to_explore = []

for path in paths:
remote_smb_path = ntpath.normpath(self.smb_cwd + ntpath.sep + path)
entries = []
Expand All @@ -210,14 +212,14 @@ def recurse_action(paths=[], depth=0, callback=None):

for entry in entries:
if entry.is_directory():
callback(entry, path + entry.get_longname() + ntpath.sep, depth)
callback(entry, path + ntpath.sep + entry.get_longname() + ntpath.sep, depth)
else:
callback(entry, path + entry.get_longname(), depth)
callback(entry, path + ntpath.sep + entry.get_longname(), depth)

# Next directories to explore
for entry in entries:
if entry.is_directory():
next_directories_to_explore.append(path + entry.get_longname() + ntpath.sep)
next_directories_to_explore.append(path + ntpath.sep + entry.get_longname() + ntpath.sep)

return next_directories_to_explore
#
Expand Down Expand Up @@ -352,6 +354,30 @@ def recurse_action(base_dir="", path=[]):
self.close_smb_session()
self.init_smb_session()

def get_entry(self, path=None):
"""
Retrieves information about a specific entry located at the provided path on the SMB share.
This method checks if the specified path exists on the SMB share. If the path exists, it retrieves the details of the entry at that path, including the directory name and file name. If the entry is found, it returns the entry object; otherwise, it returns None.
Args:
path (str): The path of the entry to retrieve information about.
Returns:
Entry: An object representing the entry at the specified path, or None if the entry is not found.
"""

if self.path_exists(path=path):
matches = self.smbClient.listPath(shareName=self.smb_share, path=path)

if len(matches) == 1:
return matches[0]
else:
return None

else:
return None

def info(self, share=True, server=True):
"""
Displays information about the server and optionally the shares.
Expand Down

0 comments on commit 30dbbbb

Please sign in to comment.