Skip to main content

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_api library

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

  1. NCUploader reads your YAML configuration file
  2. It loads credentials from .env file or environment variables
  3. It loads the existing index of previously uploaded files
  4. 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
  5. The index is updated with the current state

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ncuploader-0.2.0.tar.gz (46.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ncuploader-0.2.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

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

Hashes for ncuploader-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c712ad220e8c4a14c2383baccbeb6237c206392fa75d2375ff77923d8076323a
MD5 0a0f6f8b84b49a7517500145d4f8b7a9
BLAKE2b-256 0f7ee20111b6428b73420452f24e2e15daa4c005e0e65b2cbc80e2af2332d0a3

See more details on using hashes here.

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

Hashes for ncuploader-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ded4201c2533f99fc9a3a9362518fbda947a7cc002e16a10533ff4c70717824
MD5 0cf2bd52f9e4ceac70f72a7b26995e1d
BLAKE2b-256 431ff2dcbca5f6c9c9d8af88ddd18b705f364fd79963c4110eb73b9f38ae2978

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page