使用Python列出NAS上的所有文件夹

问题描述 投票:0回答:3

我试图用Python列出Synology NAS上的所有共享文件夹。

所以我想说我想要\\ DISKSTATION上每个文件夹的列表 例如:公共场所,家庭,电影等

那可能吗?

谢谢你的帮助!

python python-3.x nas synology
3个回答
0
投票

为什么不使用pysmb

pip install pysmb

列出共享内容:

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

将输出:

.
..
dir1
dir2
file1
file2

0
投票

如果您可以直接访问您的NAS文件夹(无需任何进一步的身份验证),您可以尝试运行python:

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

它将打印出\\DISKSTATION中的子文件夹。如果你想找到所有子文件夹,你可以关注:Getting a list of all subdirectories in the current directory


0
投票
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也可以使用像xyz.com这样的域名地址

conn.connect('xyz.com')
© www.soinside.com 2019 - 2024. All rights reserved.