Automating Photos and Media Sync with mtpcopy

Automating Photos and Media Sync with mtpcopy

Overview

mtpcopy is a command-line tool for copying files to/from MTP (Media Transfer Protocol) devices (phones, cameras, media players). Use it to automate transferring photos and media when a device connects.

Typical workflow

  1. Detect device — run mtpcopy (or an MTP listing tool) to confirm the device is visible.
  2. Mount/claim device — ensure no other process (gvfs, gphoto2, Windows services) is holding the device.
  3. Run mtpcopy with filters — copy only new or matching files (by extension, date, or size).
  4. Post-actions — delete/rename on device, move files into dated folders, update local index or cloud upload.

Example commands (Linux)

  • Copy all JPEGs from device root to local folder:

Code

mtpcopy get /DCIM/.JPG ~/Pictures/Phone/$(date +%F)/
  • Copy only newer files (assume mtpcopy supports skip-by-size/time — if not, combine with rsync-like logic after download):

Code

mtpcopy get /DCIM/.JPG ~/Pictures/Phone/ && rsync -au –remove-source-files ~/Pictures/Phone/$(date +%F)/ /final/backup/

(adapt to your mtpcopy options; many MTP tools use flags like –skip-existing or –overwrite)

Automating on connect

  • Linux (udev + systemd user service):
    1. Create a udev rule matching your device vendor/product that triggers a systemd –user service.
    2. Systemd service runs a sync script that calls mtpcopy and performs post-actions.
  • macOS: use a Folder Action or launchd job triggered by device mount (if device exposes a mount) or a small watcher script.
  • Windows: use Task Scheduler triggered by device connection (or a small PowerShell script polling for MTP device).

Example simple Linux systemd user unit + script

  • Script (/home/user/bin/phone-sync.sh):

Code

#!/bin/bash device_wait_cmd=“mtpcopy list”# replace with appropriate detection

wait for device

until \(device_wait_cmd | grep -q "YourDeviceName"; do sleep 1; done mkdir -p ~/Pictures/Phone/\)(date +%F) mtpcopy get “/Internal shared storage/DCIM/*.{JPG,MP4}” ~/Pictures/Phone/$(date +%F)/

optional: run image processing or cloud upload here

  • systemd unit (run on user login) calls the script when needed.

Reliability tips

  • Ensure exclusive access: stop gvfs/gphoto2 or any app that may lock the device before running mtpcopy.
  • Use checksums or file size checks to avoid partial/ corrupted copies.
  • Log operations and retry failed transfers.
  • Test with your specific device model — MTP behavior varies between vendors.

Alternatives / complements

  • Use libmtp-based tools (mtp-tools, mtpfs, mtpcmd) or projects that add wireless MTP (airmtp) or camera-specific sync apps if mtpcopy lacks needed features.

If you want, I can: provide a ready-to-run systemd + udev example tuned to a specific device vendor/product ID, or adapt the script to Windows/macOS — tell me which OS and device model.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *