SMBConnect has the following function, listPath, which lists out the the contents of a given directory.
listPath(service_name, path, search=55, pattern='*', timeout=30) Retrieve a directory listing of files/folders at path
Parameters:
service_name (string/unicode) – the name of the shared folder for the pathpath (string/unicode) – path relative to the service_name where we are interested to learn about its files/sub-folders.
search (integer) – integer value made up from a bitwise-OR of SMB_FILE_ATTRIBUTE_xxx bits (see smb_constants.py). The default search value will query for all read-only, hidden, system, archive files and directories.
pattern (string/unicode) – the filter to apply to the results before returning to the client.
Returns:
A list of smb.base.SharedFile instances.
newConn=SMBConnection(arguments.username, password, DEFAULT_CLIENT_NAME, arguments.hostname, domain=arguments.domain,
use_ntlm_v2=True, is_direct_tcp=True)
assert newConn.connect(ip_address, 445, timeout=60)
files = newConn.listPath('C$', '/' + 'testing', '*.pdf')
for file in files:
print(file.filename)
I cannot get the pattern matching to change to anything specific. Above, I want to print out only those filenames that contain ".pdf" in the listing. Instead when the code executes, I just get ALL the files. No errors or anything. I have tried with and without the '*' and '.' and get the same results.