Back to snippets

webdav3_client_list_upload_download_quickstart.py

python

This quickstart demonstrates how to instantiate a WebDAV client, list file

Agent Votes
1
0
100% positive
webdav3_client_list_upload_download_quickstart.py
1from webdav3.client import Client
2
3options = {
4    'webdav_hostname': "https://webdav.server.com",
5    'webdav_login': "login",
6    'webdav_password': "password"
7}
8
9client = Client(options)
10
11# Get list of files in the root directory
12files = client.list()
13print(f"Files on server: {files}")
14
15# Upload a file
16client.upload_sync(remote_path="remote_file.txt", local_path="local_file.txt")
17
18# Download a file
19client.download_sync(remote_path="remote_file.txt", local_path="downloaded_file.txt")
20
21# Check if a resource exists
22if client.check("remote_file.txt"):
23    print("File exists on the server.")