DISABLE ADBLOCK

ADBlock is blocking some content on the site

ADBlock errore

Python pysmb fetching folders correct usage

StackOverflow https://stackoverflow.com/questions/13217228

Question

I have a remote (Windows) server I'd like to connect to, and process some folder.

I tried to use SMBHandler unsuccessfully:

director = urllib2.build_opener(SMBHandler)
fh = director.open('smb://myuserID:mypassword@192.168.1.1/Publish')

It failed with the following error:

URLError: <urlopen error smb error: Failed to retrieve on Publish: Unable to open file

I wrote the following code that works perfectly using SMBConnection but I'm sure there's a better way to fetch a folder and query its subfolders and files...

conn = SMBConnection(USERID, PASSWORD, SERVER_NAME, SERVER_NAME, use_ntlm_v2 = True)
conn.connect(SERVER_IP, 139)
filelist = conn.listPath('Publish', '/')
if filelist[5].isDirectory:
    print filelist[5].filename
etc...

Can you please help me finding the most elegant way to solve my problem?

Thank you very much :)

Nili

Solution

pysmb's SMBHandler does not allow you to list the files in the folder via urllib.

As of now, what you have done using SMBConnection is the recommended way to list the files in the folder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow