1

I am trying to list all shared folders on a Synology NAS with Python.

So let's say I want a list of every folder on \\DISKSTATION
E.g.: public, homes, movies, etc

Is that possible?

Thanks for your help!

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
lojoma
  • 23
  • 1
  • 2
  • 6
  • You need just list of all folders by network path? – valex May 04 '16 at 10:14
  • Running a script to list all folders by network path is only valid for the credentials the script is running under. This may or may not bring back the information you are looking for. – Edwin van Mierlo May 04 '16 at 11:11

3 Answers3

3

Why not use pysmb?

pip install pysmb

To list share contents:

from smb.SMBConnection import SMBConnection

conn = SMBConnection('username', 'password', 'local_NetBIOS_name', 'remote_NetBIOS_name')
conn.connect('ip_address')
results = conn.listPath('share_name', '/optionally/some/subfolder')

for x in results:
    print x.filename

Will output:

.
..
dir1
dir2
file1
file2
fips
  • 4,319
  • 5
  • 26
  • 42
1
from smb.SMBConnection import SMBConnection

conn = SMBConnection('username', 'password', 'local_NetBIOS_name',   'remote_NetBIOS_name')
conn.connect('domain address')
folders = conn.listPath('share_name', '/relative/subfolder')

for folder in folders:
    print folder.filename

conn.connect can also make use of domain address like xyz.com

conn.connect('xyz.com')
raj
  • 31
  • 1
  • 4
0

if you can access your NAS folder directly (without any further authentication), you may try to run python:

import os
os.listdir(r'\\DISKSTATION')

it will print out the subfolders in \\DISKSTATION. if you want to find all subfolders, you may follow: Getting a list of all subdirectories in the current directory

Community
  • 1
  • 1
Guoliang
  • 885
  • 2
  • 12
  • 20