A Python-based CLI service that synchronizes a local directory with a remote directory on a USB device via MTP.
- Synchronize files and folders from local storage to MTP devices (like Android phones, digital cameras, etc.)
- Verify-only option to check what will be synchronized before making changes
- Checksum validation to ensure file integrity
- Support for automatic retry of failed transfers
- Interactive device and storage selection
- Python 3.11+
- libmtp (system library)
-
Install libmtp on your system:
- MacOS:
brew install libmtp - Ubuntu/Debian:
sudo apt-get install libmtp-dev - Fedora/RHEL:
sudo dnf install libmtp-devel - Windows: Download and install libmtp
- MacOS:
-
Install the Python package requirements:
pip install -r mtpsync/requirements.txt
Basic usage:
python -m mtpsync.cli /path/to/source/directoryThis will:
- Detect MTP devices
- Prompt for device selection if multiple are connected
- Prompt for storage selection if multiple are available
- Verify the differences between source and destination
- Generate an execution plan
- Ask if you want to proceed with synchronization
Usage: mtpsync [OPTIONS] SOURCE_DIR
Options:
--dest PATH Destination path (e.g. "/DCIM")
--storage ID MTP storage ID (prompted if missing)
--mode [verify|exec] Flow mode (verify by default)
--checksum / --no-checksum Validate via SHA256 (default: enabled)
--plan PATH Path to execution plan JSON
-h, --help Show help message
Synchronize a photo directory to the DCIM folder on your device:
python -m mtpsync.cli ~/Pictures/vacation --dest /DCIM/vacationVerify what will be synchronized without transferring any files:
python -m mtpsync.cli ~/Documents/important --mode verifyExecute a previously generated sync plan:
python -m mtpsync.cli ~/Music --mode exec --plan ./custom_plan.jsonmtpsync/
├── cli.py - Command line interface
├── mtp_client.py - Libmtp bindings and client
├── sync.py - Synchronization engine
├── models.py - Data structures
├── config.py - Configuration and constants
├── utils/ - Utility functions
│ ├── checksum.py - File checksum utilities
│ ├── retries.py - Retry logic
│ └── prompt.py - User interaction
├── data/ - Execution plans
└── logs/ - Log files
Run tests using pytest:
pytest