1 year ago
#322867
NicLovin
Can you traverse Synology NAS using Python?
Using the python request module and the official Synology documentation:
I have successfully retrieved API information, logged in, and requested for the File Station API. I've included my current code below:
import requests
if __name__ == '__main__':
# Retrieve API Information
response = requests.get("https://myds.com:port/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query&query=SYNO.API.Auth,SYNO.FileStation.List")
print(response.json())
# login
response = requests.get("https://myds.com:port/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account="+str(user)+
"&passwd="+str(password)+"&session=FileStation&format=sid")
print(response.json())
sid = (response.json()['data']['sid'])
# request File Station API
response = requests.get("https://myds.com:port/webapi/entry.cgi/?api=SYNO.FileStation.List&version=2&method=list_share&_sid="+sid)
print(response.json())
# logout
requests.get("https://myds.com:port/webapi/auth.cgi?api=SYNO.API.Auth&version=6&method=logout&session=FileStation")
Doing this I can view the folders in the NAS, and looking at the Synology documentation I can download a specified folder or file within the drive with SYNO.FileStation.Download.
What I am wondering is there a way to use python to traverse subfolders within the drive and only download certain files (say based off of filename). I can't just download the main folder and then traverse it on my local machine (for example using the python OS module and the os.listdir() method) because it is extremely large so I need to do it through the APIs.
python
synology
0 Answers
Your Answer