Search code examples
pythonsmb

Can't access share drive on windows machine from Python


I have a windows machine with a server name 'HPTOUCH'. I also have a share directory called 'Movies' on this windows machine. In raspian rasp pi using python 2.7, I am writing a simple test program to access the windows directory from the Pi. I've tried all the suggestions here, i.e.

    os.listdir(r'\\HPTOUCH\Movies')
    os.listdir('\\\\HPTOUCH\\Movies')
    os.listdir(r'\\192.168.1.103\Movies')
    os.listdir('////HPTOUCH//Movies')
    os.listdir(r'\\smb://HPTOUCH//Movies')

Well, you get the idea. I keep getting an error: No such file or directory. What am I doing wrong. If I am in XBMC, I can easily access any movie on that drive, so permissions seem to be OK. What is the python code for accessing a windows share?


Solution

  • Linux (under XBMC) doesn't support UNC style paths. You either have to mount the remote filesystem first, use an existing mount point or use https://pythonhosted.org/pysmb/ library.

    To mount your remote server:

    smbmount //192.168..103/Movies /mnt/movies –o "username=Tony,password=mypass"