from smb.SMBConnection import SMBConnection # Creating an SMBConnection object conn = SMBConnection('username', 'password', 'myclient', 'smbserver') # Connecting to the SMB/CIFS server connected = conn.connect('smbserver', 139)
# Listing files on a remote directory share_name = 'shared_folder' path = '/remote_directory/' # Reading directory contents files = conn.listPath(share_name, path) # Printing file names and sizes for file in files: print(file.filename) print(file.file_size)This code lists the files in the specified directory on the remote server, and prints their names and sizes. Package library: pysmb.