sh4den/Montscan

🖨️ Self-hosted scanned document processor with AI-powered naming. Receives scans via FTP, SFTP, SCP, SMB or a watched folder, reads them with a local Ollama vision model, gives each file a dated, descriptive name, and delivers it to WebDAV (Nextcloud, ownCloud), an SMB share, or a local folder.

Montscan is an automated document processor for network scanners. It receives scanned PDFs through several common file-transfer methods, uses a local AI vision model to understand each document, gives it a descriptive filename, and then delivers it to a chosen destination (like a cloud drive or network share). It's written in Rust and is currently in active development—not fully production-ready, but it reports a 97.5% success rate on a small test set of 1,000 documents.

How it works

Montscan runs as a single binary that listens for incoming files. You can enable one or more "ingress" methods:

  • FTP – a classic file-transfer server
  • SFTP – secure file transfer over SSH
  • SCP – the older secure copy protocol
  • Samba (SMB) – polls a shared network folder for new PDFs
  • Folder watcher – monitors a local directory

Once a PDF arrives, Montscan uses Ollama (a local AI runner) with a vision model to analyze the content and generate a human-readable, date-aware filename (e.g., Invoice_2025-03-14.pdf). If AI naming fails or times out, it falls back to a timestamped name like scan_20250314_123456.pdf.

After processing, the file is delivered via one of the "egress" options (in priority order):

  • WebDAV – upload to Nextcloud, ownCloud, or any WebDAV server
  • Samba – push to an SMB/CIFS network share
  • Local move – if the folder watcher is used, files can be renamed in place or moved to an output folder

If no egress is configured, files are simply left where they landed.

Architecture

Montscan is a single Rust crate. Each ingress is a separate module that implements a common Ingress trait, so adding a new protocol doesn't touch the AI or delivery code. PDF pages are rendered in-process (no external tools needed). The project uses several Rust libraries for protocols (e.g., libunftp for FTP, russh for SSH/SFTP/SCP, smb for Samba) and hayro for PDF rendering.

Configuration

Everything is configured via environment variables. You must enable at least one ingress. Common settings include:

  • FTP_ENABLED, FTP_PORT, FTP_USERNAME, FTP_PASSWORD – for the FTP server
  • SFTP_ENABLED, SCP_ENABLED – for SSH-based ingresses
  • SAMBA_SERVER_* – for polling a remote SMB share
  • FOLDER_ENABLED, FOLDER_INPUT_DIR, FOLDER_OUTPUT_DIR – for local folder watching
  • WEBDAV_* – for WebDAV upload
  • SAMBA_* – for Samba upload
  • OLLAMA_HOST, OLLAMA_MODEL, OLLAMA_TIMEOUT – AI settings
  • LANGUAGE – language for AI-generated filenames

Defaults are provided for most variables. For example, FTP is enabled by default on port 21 with username scanner and password scanner123.

Usage

Typical setups:

  • Scanner → FTP → WebDAV: Enable FTP and WebDAV, set credentials and URLs.
  • Scanner → Samba share → folder watcher → output folder: Point the folder watcher at a mounted Samba share, and it renames and moves files.
  • Scanner → Samba share → folder watcher → rename in place: Same but without an output directory.

To run locally, build with cargo build --release, set environment variables (e.g., from a .env file), and run the binary. Logging uses RUST_LOG (default info).

Docker

Montscan provides a docker-compose.yml that uses a prebuilt image from GitHub Container Registry. You can also build from source. For GPU acceleration of Ollama, set COMPOSE_PROFILES=gpu and OLLAMA_GPU_COUNT=1. Ports for FTP, SFTP, and SCP need to be published, and a volume for ./storage is recommended to persist received files and SSH host keys.

Troubleshooting

Common issues and fixes are documented:

  • FTP connection refused – check firewall
  • FTP hangs in Docker – publish passive ports and set FTP_PASSIVE_HOST
  • SCP fails with "subsystem request failed" – use scp -O or point to the SFTP port
  • SSH host key warning – keep the key on a persistent volume
  • Folder watcher not picking up files – check paths and permissions
  • AI naming fails – ensure Ollama is running with a vision model; it falls back to timestamp names
  • WebDAV upload fails – check credentials, URL, and path; try WEBDAV_INSECURE=true for self-signed certs
  • PDF parse errors – password-protected PDFs are not supported

License

Montscan is MIT licensed. The README also acknowledges the libraries it builds upon (libunftp, russh, smb-rs, Ollama, reqwest).

For more details, see the full README on GitHub.

Related

  • Project
  • Project
  • Project
  • Project
  • Project