Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import urllib3
- # Suppress InsecureRequestWarning
- urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
- def get_json(url):
- response = requests.get(url, verify=False)
- return response.json()
- def download_file(url, sid, file_path):
- headers = {'Cookie': f'id={sid}'}
- response = requests.post(url, headers=headers, verify=False)
- if response.status_code == 200:
- with open(file_path, 'wb') as file:
- file.write(response.content)
- print(f"File successfully downloaded to: {file_path}")
- else:
- print("Failed to download the file.")
- def main():
- host = "xxx"
- user = "xxx"
- password = "xxx."
- # Login and obtain session ID
- login_url = f"https://{host}/webapi/auth.cgi?api=SYNO.API.Auth&method=login&version=3&account={user}&passwd={password}&session=FileStation&format=sid"
- login_response = get_json(login_url)
- print(f"Login response: {login_response}")
- if "data" in login_response and "sid" in login_response["data"]:
- sid = login_response["data"]["sid"]
- print(f"Login successful. Session ID: {sid}")
- # URL to download the file
- download_url = f"https://{host}/webapi/entry.cgi?api=SYNO.ActiveBackupOffice365&method=download_file&version=1&SynoHash=bWP_dbnWIHl-lmFtCp1qNIvpoRwSrA.NzI&SynoToken=.vLMwHcu.wwuE"
- file_path = "C:\\scripts\\ActiveBackup_Activity_Log.csv"
- # Download the file
- download_file(download_url, sid, file_path)
- # Logout
- logout_url = f"https://{host}/webapi/auth.cgi?api=SYNO.API.Auth&method=logout&version=3&session=FileStation&_sid={sid}"
- logout_response = get_json(logout_url)
- if logout_response["success"]:
- print("Logout successful.")
- else:
- print("Logout failed.")
- else:
- print("Login failed. Check the username, password, or API endpoints.")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement