OwnCloud is an open-source file hosting platform that provides cloud storage with privacy and control. In German research institutions, it’s commonly accessed through Sciebo, a cloud storage service for universities and research institutions.
Why ownCloud (via Sciebo)?
- University Hosted: Data stays within German/European university infrastructure
- GDPR Compliant: Meets European data protection requirements
- Large Storage: Generous storage quotas for research data
- Programmatic Access: Python API for automation
- WebDAV Protocol: Standard file access protocol
Python Client Basics
Connecting to Sciebo
import owncloud
# Connect with credentials
oc = owncloud.Client('https://uni-muenster.sciebo.de')
oc.login('username', 'password')
# List files in root
files = oc.list('/')
for file_info in files:
print(file_info.get_name())
# Logout
oc.logout()
Downloading Files from Public Links
import owncloud
# Connect to public share (no login needed)
public_link = 'https://uni-muenster.sciebo.de/s/AbCdEfGh'
oc = owncloud.Client.from_public_link(public_link)
# Download specific file
oc.get_file(
'/dataset.csv',
'local_path/dataset.csv'
)
Common Research Workflows
Downloading Shared Datasets
from pathlib import Path
import owncloud
# Setup
public_link = 'https://uni-muenster.sciebo.de/s/DataShare123'
output_dir = Path('data/raw')
output_dir.mkdir(parents=True, exist_ok=True)
# Connect and download
oc = owncloud.Client.from_public_link(public_link)
# Download all files
files = oc.list('/')
for file_info in files:
if file_info.is_dir():
continue
filename = file_info.get_name()
local_path = output_dir / filename
print(f"Downloading {filename}...")
oc.get_file(f'/{filename}', str(local_path))
Downloading Specific File Types
import owncloud
from pathlib import Path
# Connect
oc = owncloud.Client.from_public_link(public_link)
# Download only CSV files
output_dir = Path('data')
for file_info in oc.list('/'):
if file_info.get_name().endswith('.csv'):
remote_path = f"/{file_info.get_name()}"
local_path = output_dir / file_info.get_name()
oc.get_file(remote_path, str(local_path))
print(f"Downloaded: {file_info.get_name()}")
Uploading Results
import owncloud
# Connect with authentication
oc = owncloud.Client('https://uni-muenster.sciebo.de')
oc.login('username', 'password')
# Upload file
oc.put_file(
'/Research/results/analysis.csv', # Remote path
'local_results/analysis.csv' # Local file
)
# Create directory first if needed
oc.mkdir('/Research/results')
# Upload multiple files
from pathlib import Path
results_dir = Path('results')
for file_path in results_dir.glob('*.csv'):
remote_path = f'/Research/results/{file_path.name}'
oc.put_file(remote_path, str(file_path))
print(f"Uploaded: {file_path.name}")
Checking File Information
# Get file info
file_info = oc.file_info('/path/to/file.csv')
print(f"Name: {file_info.get_name()}")
print(f"Size: {file_info.get_size()} bytes")
print(f"Modified: {file_info.get_last_modified()}")
print(f"Type: {file_info.get_content_type()}")
# Check if exists
try:
info = oc.file_info('/dataset.csv')
print("File exists")
except:
print("File not found")
Practical Examples for Teaching
Download Course Materials
import owncloud
from pathlib import Path
def download_course_materials(public_link, output_dir='course_data'):
"""Download all course materials from Sciebo share."""
output_path = Path(output_dir)
output_path.mkdir(parents=True, exist_ok=True)
# Connect
oc = owncloud.Client.from_public_link(public_link)
# Download all files
for file_info in oc.list('/'):
if file_info.is_dir():
continue
filename = file_info.get_name()
local_file = output_path / filename
# Skip if already downloaded
if local_file.exists():
print(f"Skipping {filename} (already exists)")
continue
print(f"Downloading {filename}...")
oc.get_file(f'/{filename}', str(local_file))
print(f"\nAll files downloaded to {output_path}")
# Usage
share_link = 'https://uni-muenster.sciebo.de/s/CourseData'
download_course_materials(share_link)
Automated Data Sync
import owncloud
from pathlib import Path
import time
def sync_directory(username, password, remote_dir, local_dir):
"""Sync remote Sciebo directory to local."""
oc = owncloud.Client('https://uni-muenster.sciebo.de')
oc.login(username, password)
local_path = Path(local_dir)
local_path.mkdir(parents=True, exist_ok=True)
# Get remote files
remote_files = oc.list(remote_dir)
for file_info in remote_files:
if file_info.is_dir():
continue
filename = file_info.get_name()
remote_path = f"{remote_dir}/{filename}"
local_file = local_path / filename
# Check if needs update
if local_file.exists():
remote_mtime = file_info.get_last_modified()
local_mtime = local_file.stat().st_mtime
if remote_mtime <= local_mtime:
continue # Local is up to date
print(f"Syncing {filename}...")
oc.get_file(remote_path, str(local_file))
oc.logout()
WebDAV Alternative
For more flexibility, you can use webdav4 directly:
from webdav4.client import Client
# Connect
client = Client(
'https://uni-muenster.sciebo.de/remote.php/webdav',
auth=('username', 'password')
)
# Download file
client.download_file(
'/remote/path/file.csv',
'local/path/file.csv'
)
# Upload file
client.upload_file(
'local/file.csv',
'/remote/path/file.csv'
)
Error Handling
import owncloud
try:
oc = owncloud.Client.from_public_link(public_link)
oc.get_file('/dataset.csv', 'local_dataset.csv')
except owncloud.HTTPResponseError as e:
print(f"HTTP Error: {e}")
except Exception as e:
print(f"Error downloading file: {e}")
Environment Variables for Credentials
import os
import owncloud
# Store credentials in .env file (never commit to git!)
SCIEBO_USER = os.getenv('SCIEBO_USER')
SCIEBO_PASSWORD = os.getenv('SCIEBO_PASSWORD')
oc = owncloud.Client('https://uni-muenster.sciebo.de')
oc.login(SCIEBO_USER, SCIEBO_PASSWORD)
Installation
pixi add pyocclient
# or
pip install pyocclient
For WebDAV alternative:
pixi add webdav4
# or
pip install webdav4
Best Practices
- Use public links for sharing datasets (no authentication needed)
- Never commit credentials to version control
- Use environment variables or .env files for credentials
- Check if files already exist before downloading
- Use try-except for robust error handling
- Logout when done with authenticated sessions
- Consider webdav4 for more advanced features
- Use Path objects for cross-platform compatibility
- Document share links in README files
- Provide alternative download methods for reproducibility
Security Notes
- Never share passwords in code or notebooks
- Use app-specific passwords when available
- Public share links don’t require authentication
- Consider link expiration dates for shared data
- Be aware of file permissions when uploading