from smb import SMBConnection conn = SMBConnection('username', 'password', 'localhost', 'remote_share') conn.connect('remote_IP') # List all files and directories in the root directory of the share results = conn.listPath('/', '') for item in results: print(item.filename)
from smb import SMBConnection conn = SMBConnection('username', 'password', 'localhost', 'remote_share') conn.connect('remote_IP') # List all text files in the root directory of the share results = conn.listPath('/', '*.txt') for item in results: print(item.filename)This code example lists only text files in the root directory of the remote share. The second argument passed to the listPath() method is a pattern that filters the results to only include files with .txt extensions. The smb.SMBConnection library is part of the pysmb package, which provides comprehensive support for various SMB/CIFS-related protocols.