I am using the python-smbc library on Ubuntu to access a samba share. I can access the directory structure fine, I am however not sure how to access actual files and their c
Provided you have an open context (see the unit tests here)
* https://github.com/ioggstream/pysmbc/tree/master/tests
suri = 'smb://' + settings.SERVER + '/' + settings.SHARE + '/test.dat'
dpath = '/tmp/destination.out'
# open smbc uri
sfile = ctx.open(suri, os.O_RDONLY)
# open local target where to copy file
dfile = open(dpath, 'wb')
#copy file and flush
dfile.write(sfile.read())
dfile.flush()
#close both files
sfile.close()
dfile.close()
To open a context just define an authentication function
ctx = smbc.Context()
def auth_fn(server, share, workgroup, username, password):
return (workgroup, settings.USERNAME, settings.PASSWORD)
ctx.optionNoAutoAnonymousLogin = True
ctx.functionAuthData = auth_fn