WebDAV client library providing easy access to cloud storage services like Yandex.Drive, Dropbox, Google Drive, Box, and 4shared.
Upload and download operations with support for both synchronous and asynchronous execution, progress callbacks, and directory synchronization. These operations handle the transfer of files and directories between local filesystem and WebDAV servers.
Downloads files and directories from WebDAV server to local filesystem with various execution modes and progress tracking.
def download_to(self, buff, remote_path: str) -> None:
"""
Download remote file content to buffer.
Parameters:
- buff: buffer object to write content to
- remote_path: str, path to remote file
Raises:
- RemoteResourceNotFound: if remote file doesn't exist
- NotConnection: if connection to server fails
"""
def download(self, remote_path: str, local_path: str, progress=None) -> None:
"""
Download file or directory with optional progress callback.
Parameters:
- remote_path: str, path to remote resource
- local_path: str, local destination path
- progress: callable, progress callback function
Raises:
- RemoteResourceNotFound: if remote resource doesn't exist
- LocalResourceNotFound: if local parent directory doesn't exist
- NotConnection: if connection to server fails
"""
def download_sync(self, remote_path: str, local_path: str, callback=None) -> None:
"""
Synchronously download remote resource to local path.
Parameters:
- remote_path: str, path to remote resource
- local_path: str, local destination path
- callback: callable, completion callback function
Raises:
- RemoteResourceNotFound: if remote resource doesn't exist
- LocalResourceNotFound: if local parent directory doesn't exist
- NotConnection: if connection to server fails
"""
def download_async(self, remote_path: str, local_path: str, callback=None) -> None:
"""
Asynchronously download remote resource with callback.
Parameters:
- remote_path: str, path to remote resource
- local_path: str, local destination path
- callback: callable, completion callback function
Note: Operation runs in background thread
"""
def download_directory(self, remote_path: str, local_path: str, progress=None) -> None:
"""
Download entire directory recursively.
Parameters:
- remote_path: str, path to remote directory
- local_path: str, local destination directory
- progress: callable, progress callback for tracking
Raises:
- RemoteResourceNotFound: if remote directory doesn't exist
- NotConnection: if connection to server fails
"""
def download_file(self, remote_path: str, local_path: str, progress=None) -> None:
"""
Download single file with progress tracking.
Parameters:
- remote_path: str, path to remote file
- local_path: str, local destination file path
- progress: callable, progress callback function
Raises:
- RemoteResourceNotFound: if remote file doesn't exist
- NotConnection: if connection to server fails
"""Uploads files and directories from local filesystem to WebDAV server with various execution modes and progress tracking.
def upload_from(self, buff, remote_path: str) -> None:
"""
Upload buffer content to remote file.
Parameters:
- buff: buffer object containing data to upload
- remote_path: str, destination path on remote server
Raises:
- RemoteParentNotFound: if remote parent directory doesn't exist
- NotConnection: if connection to server fails
- NotEnoughSpace: if insufficient space on server
"""
def upload(self, remote_path: str, local_path: str, progress=None) -> None:
"""
Upload file or directory with optional progress callback.
Parameters:
- remote_path: str, destination path on remote server
- local_path: str, path to local resource
- progress: callable, progress callback function
Raises:
- LocalResourceNotFound: if local resource doesn't exist
- RemoteParentNotFound: if remote parent directory doesn't exist
- NotConnection: if connection to server fails
- NotEnoughSpace: if insufficient space on server
"""
def upload_sync(self, remote_path: str, local_path: str, callback=None) -> None:
"""
Synchronously upload local resource to remote path.
Parameters:
- remote_path: str, destination path on remote server
- local_path: str, path to local resource
- callback: callable, completion callback function
Raises:
- LocalResourceNotFound: if local resource doesn't exist
- RemoteParentNotFound: if remote parent directory doesn't exist
- NotConnection: if connection to server fails
- NotEnoughSpace: if insufficient space on server
"""
def upload_async(self, remote_path: str, local_path: str, callback=None) -> None:
"""
Asynchronously upload local resource with callback.
Parameters:
- remote_path: str, destination path on remote server
- local_path: str, path to local resource
- callback: callable, completion callback function
Note: Operation runs in background thread
"""
def upload_directory(self, remote_path: str, local_path: str, progress=None) -> None:
"""
Upload entire directory recursively.
Parameters:
- remote_path: str, destination directory on remote server
- local_path: str, path to local directory
- progress: callable, progress callback for tracking
Raises:
- LocalResourceNotFound: if local directory doesn't exist
- RemoteParentNotFound: if remote parent directory doesn't exist
- NotConnection: if connection to server fails
- NotEnoughSpace: if insufficient space on server
"""
def upload_file(self, remote_path: str, local_path: str, progress=None) -> None:
"""
Upload single file with progress tracking.
Parameters:
- remote_path: str, destination file path on remote server
- local_path: str, path to local file
- progress: callable, progress callback function
Raises:
- LocalResourceNotFound: if local file doesn't exist
- RemoteParentNotFound: if remote parent directory doesn't exist
- NotConnection: if connection to server fails
- NotEnoughSpace: if insufficient space on server
"""import webdav.client as wc
client = wc.Client({
'webdav_hostname': "https://webdav.server.com",
'webdav_login': "username",
'webdav_password': "password"
})
# Download single file
client.download_sync("documents/report.pdf", "~/Downloads/report.pdf")
# Download with progress tracking
def show_progress(current, total):
percentage = (current / total) * 100
print(f"Download progress: {percentage:.1f}%")
client.download_file("documents/large_file.zip", "~/Downloads/large_file.zip", progress=show_progress)# Download entire directory
client.download_directory("projects/webapp/", "~/Downloads/webapp/")
# Asynchronous download with callback
def download_complete(success, error=None):
if success:
print("Download completed successfully")
else:
print(f"Download failed: {error}")
client.download_async("backup/archive.tar.gz", "~/Downloads/archive.tar.gz", callback=download_complete)# Upload single file
client.upload_sync("documents/new_report.pdf", "~/Documents/report.pdf")
# Upload with progress tracking
def upload_progress(current, total):
percentage = (current / total) * 100
print(f"Upload progress: {percentage:.1f}%")
client.upload_file("media/video.mp4", "~/Videos/presentation.mp4", progress=upload_progress)# Upload entire directory
client.upload_directory("projects/website/", "~/Development/website/")
# Asynchronous upload with callback
def upload_complete(success, error=None):
if success:
print("Upload completed successfully")
else:
print(f"Upload failed: {error}")
client.upload_async("backup/project.zip", "~/Projects/backup.zip", callback=upload_complete)from io import BytesIO
# Download to buffer
buffer = BytesIO()
client.download_to(buffer, "data/config.json")
buffer.seek(0)
config_data = buffer.read()
# Upload from buffer
data = b"Hello, WebDAV!"
upload_buffer = BytesIO(data)
client.upload_from(upload_buffer, "messages/greeting.txt")import time
class ProgressTracker:
def __init__(self, description):
self.description = description
self.start_time = time.time()
def __call__(self, current, total):
percentage = (current / total) * 100
elapsed = time.time() - self.start_time
speed = current / elapsed if elapsed > 0 else 0
print(f"{self.description}: {percentage:.1f}% ({current}/{total} bytes) - {speed:.0f} B/s")
# Use progress tracker
tracker = ProgressTracker("Downloading report")
client.download_file("reports/annual_report.pdf", "~/Downloads/annual_report.pdf", progress=tracker)Install with Tessl CLI
npx tessl i tessl/pypi-webdavclient