One way of handling samba is to use pysmb
. If so, then it goes something like the following:
# we need to provide localhost name to samba
hostname = socket.gethostname()
local_host = (hostname.split('.')[0] if hostname
else "SMB{:d}".format(os.getpid()))
# make a connection
cn = SMBConnection(
<username>, <password>, local_host, <netbios_server_name>,
domain=<domain>, use_ntlm_v2=<use_ntlm_v2>,
is_direct_tcp=<self.is_direct_tcp>)
# connect
if not cn.connect(<remote_host>, <remote_port>):
raise IOError
# working connection ... to check if a directory exists, ask for its attrs
attrs = cn.getAttributes(<shared_folder_name>, <path>, timeout=30)
Some notes:
in your example above, public_pictures
is the shared folder
, while path
would be simply /
you'll need to know if you are using SMB on port 139
or 445
(or a custom port). If the latter you will usually want to pass is_direct_tcp=True
(although some servers will still serve NetBIOS samba on 445
)
if you expect not to need a username or password, then probably you are expecting to connect as username="guest"
with an empty password.