A CLI tool to upload files and directories to Nextcloud with support for retention policies, dry-run, and tilde expansion for local paths.
Project description
NCUploader
NCUploader is a modern Python tool for managing file uploads to Nextcloud servers with retention policy management. It provides a seamless way to automate the process of uploading files and directories to Nextcloud while maintaining control over how long they should be retained.
Features
- Upload files and directories to Nextcloud
- Track uploaded files with a local index
- Apply retention policies (e.g., remove files 30 days after upload)
- Simple YAML configuration
- Load credentials from .env file for better security
- Colorized terminal output
- Comprehensive logging
- Command-line interface
Requirements
- Python 3.12+
- Nextcloud server
nc_py_apilibrary
Installation
# Using uv (recommended)
uv pip install ncuploader
# Using pip
pip install ncuploader
Configuration
NCUploader uses a YAML configuration file to define upload sources, destinations, and retention policies:
# ncuploader.yaml
nextcloud:
url: "https://your-nextcloud-instance.com"
username: "your_username"
password: "your_password" # Consider using .env file instead
uploads:
- local_path: "~/path/to/local/file.txt" # ~ is expanded to your home directory
remote_path: "/remote/destination/file.txt"
retention_policy:
delete_after_upload: "30d" # Supported formats: Xd (days), Xw (weeks), Xm (months)
- local_path: "~/path/to/local/directory" # ~ is expanded to your home directory
remote_path: "/remote/destination/directory"
retention_policy:
delete_after_upload: "2w"
Using .env for Credentials
For better security, you can use a .env file to store your credentials:
# .env
NEXTCLOUD_URL=https://your-nextcloud-instance.com
NEXTCLOUD_USERNAME=your_username
NEXTCLOUD_PASSWORD=your_super_secret_password
# NEXTCLOUD_TOKEN=your_super_secret_token # Alternative to password
Then, your YAML config can omit sensitive information:
# ncuploader.yaml (credentials loaded from .env)
nextcloud:
# Credentials loaded from .env file
uploads:
- local_path: "~/path/to/local/file.txt" # ~ is expanded to your home directory
remote_path: "/remote/destination/file.txt"
retention_policy:
delete_after_upload: "30d"
Usage
Command Line
# Upload using the default config file (ncuploader.yaml in current directory)
ncuploader
# Specify a custom config file
ncuploader --config /path/to/config.yaml
# Run in dry-run mode (no actual uploads or deletions)
ncuploader --dry-run
# Show verbose output
ncuploader --verbose
Environment Variables
In addition to using a .env file, you can also use environment variables directly:
export NEXTCLOUD_URL="https://your-nextcloud-instance.com"
export NEXTCLOUD_USERNAME="your_username"
export NEXTCLOUD_PASSWORD="your_password"
How It Works
- NCUploader reads your YAML configuration file
- It loads credentials from .env file or environment variables
- It loads the existing index of previously uploaded files
- For each path in your configuration:
- If not in the index: uploads to Nextcloud and adds to the index
- If already in the index: checks the retention policy and removes if needed
- The index is updated with the current state
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ncuploader-0.2.0.tar.gz.
File metadata
- Download URL: ncuploader-0.2.0.tar.gz
- Upload date:
- Size: 46.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c712ad220e8c4a14c2383baccbeb6237c206392fa75d2375ff77923d8076323a
|
|
| MD5 |
0a0f6f8b84b49a7517500145d4f8b7a9
|
|
| BLAKE2b-256 |
0f7ee20111b6428b73420452f24e2e15daa4c005e0e65b2cbc80e2af2332d0a3
|
File details
Details for the file ncuploader-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ncuploader-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ded4201c2533f99fc9a3a9362518fbda947a7cc002e16a10533ff4c70717824
|
|
| MD5 |
0cf2bd52f9e4ceac70f72a7b26995e1d
|
|
| BLAKE2b-256 |
431ff2dcbca5f6c9c9d8af88ddd18b705f364fd79963c4110eb73b9f38ae2978
|