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
If don't know if this is more clearly stated, but here's what I gleaned from this page and sorted out from a little extra Google-ing:
def do_auth (server, share, workgroup, username, password):
return ('MYDOMAIN', 'myacct', 'mypassword')
# Create the context
ctx = smbc.Context (auth_fn=do_auth)
destfile = "myfile.txt"
source = open('/home/myuser/textfile.txt', 'r')
# open a SMB/CIFS file and write to it
file = ctx.open ('smb://server/share/folder/'+destfile, os.O_CREAT | os.O_WRONLY)
for line in source:
file.write (line)
file.close()
source.close()
# open a SMB/CIFS file and read it to a local file
source = ctx.open ('smb://server/share/folder/'+destfile, os.O_RDONLY)
destfile = "/home/myuser/textfile.txt"
fle = open(destfile, 'w')
for line in source:
file.write (line)
file.close()
source.close()