Python can only handle local paths.
Samba is a remote path read by a driver or application in your Linux system and can there for not be directly accessed from Python unless you're using a custom library like this experimental library.
You could do something similar to (make sure your user has the permission needed to mount stuff):
import os
from subprocess import Popen, PIPE, STDOUT
# Note: Try with shell=True should not be used, but it increases readability to new users from my years of teaching people Python.
process = Popen('mkdir ~/mnt && mount -t cifs //myserver_ip_address/myshare ~/mnt -o username=samb_user,noexec', shell=True, stdout=PIPE, stderr=PIPE)
while process.poll() is None:
print(process.stdout.readline()) # For debugging purposes, in case it asks for password or anything.
print(os.listdir('~/mnt'))
Again, using shell=True
is dangerous, it should be False
and you should pass the command-string as a list. But for some reason it appears "complex" if you use it the way you're supposed to, so i'll write you this warning and you can choose to follow common guidelines or just use this to try the functionality out.
Here's a complete guide on how to manually mount samba. Follow this, and replace the manual steps with automated programming.
smb
is a protocol picked up my the samba driver. This is not a universal path accessible by any other applications. What Linux does is mounting the remote SMB folder to a local folder via the driver giving you access to it. Either Mount it, or find a Python library that supports samba. – Jeffrey