Accessing Photos over PTP/MTP like a Filesystem
A review of the ways we've got today on Linux to access photos from a camera or a phone like files on a filesystem, many of which involve using FUSE.
The Picture Transfer Protocol – PTP – and Media Transfer Protocol – MTP – are some of those I wonder why they even have to exist. Why can't cameras and phones just make it possible to mount their filesystem and access their files so we can work e.g. with the photos with take? It's just flash memory with usually a FAT filesystem which any system can read, after all.
Anyway, in the early 2000s, some thought it'd be a good idea to hide the filesystem behind this kind of transfer protocols. Luckily, some other people decided to go full circle and hide PTP and MTP behind a filesystem again. This post is a review of the offering on Linux, tested on FUSE 7.19.
If the name PTP refers to Pictures, its scope has become much broader which smartphones and it's now also used to access in essence any kind of files that your phone will make accessible. From its name, it's tempting to think that MTP replaced PTP in every way to access Media. Yet, PTP implementations seem to work more better in practice. Either way, it appears that having comfortable means to use PTP and MTP is becoming more essential than ever.
1 GPhotoFS
GPhotoFS is based on FUSE and uses libgphoto2
which, in my mind, is the standard on Linux to access photos over PTP. GPhotoFS is fast, easy to use, well documented. Plug your device in, and run:
% mkdir mnt
% gphotofs mnt
... to mount your filesystem. Unmount it involves using the standard FUSE command:
% fusermount -u mnt
The GPhotoFS manual page will tell your that it doesn't know how to add or remove directories. Surprisingly, it really can, though. When you think about it, why would it not have been able to, anyway? PTP, MTP and libgphoto2
do support it after all. The basic gphoto2
command does come with the --mkdir
and --rmdir
command-line options which do exactly this too.
What's disturbing however is that I've had the case with GPhotoFS 2.9.4 that some files which I know were were there were not listed.
Interestingly, mounting the phone over MTP instead of PTP will show you at least one top-level directory but descending into it yields an I/O error. Fair enough, GPhotoFS wasn't advertised to support MTP.
2 GVfs
I once described how to mount a FUSE filesystem over PTP/MTP with GVfs:
% /usr/lib/gvfs/gvfsd-fuse ~/.gvfs
% gvfs-mount "gphoto2://[$(gphoto2 --auto-detect | awk 'END { print $NF }')]"
The question arises whether you'd prefer your device to present to you the PTP or MTP protocol. It doesn't seem to matter too much in practice. Unmounting is carried out this way:
% gvfs-mount -u "gphoto2://[$(gphoto2 --auto-detect | awk 'END { print $NF }')]"
Overall, it feels rather dodgy. It will take several attempts to mount before succeeding. Listing all the files often raises several I/O errors. But when it doesn't, it's interesting to see that it will find those files which GPhotoFS also should have found but didn't.
Remarkably, finding all the files over PTP will result in the same list as GPhotoFS. It appears that there's something wrong with whichever underlying component there is to use PTP. This is GVfs 1.28.1.
3 Go-mtpfs
Written in Go, Go-mtpfs feels slower, easily hits time-outs and seems rather flaky. On one device, listing the files yielded I/O errors left, right and centre. It behaved a bit better on another device. This was a 20150802 git snapshot. Unlike GVfs, mounting and unmounting is fairly straightforward:
% go-mtpfs mnt
% fusermount -u mnt
This is really intended for MTP only, no PTP support there.
4 jmtpfs
It seems that jmtpfs is a bit picky on the device too. Some will work, some other ones won't as of version 0.5. No particular drama otherwise when listing the files. Mounting and unmounting is fairly straightforward here too:
% jmtpfs mnt
% fusermount -u mnt
I naively tried PTP too, but jmtpfs is really only meant for MTP, as the name suggests.
5 MTPfs
I've never been able to get it to work on any device. Mounting seemed to be working, as did unmounting. But trying to access anything under the mount point kept yielding the Transport endpoint is not connected error message.
% mtpfs mnt
% fusermount -u mnt
I naively tried PTP too, but MTPfs is really only meant for MTP, as the name suggests. Or so it would be if it worked in practice.
6 Summary
The two smartphones are of different makes, have different Android version and different file sets. I attempted to list all the files with the find
command and measure how long it took. These times are reproducible:
Samsung | Acer | |
---|---|---|
GPhotoFS | 35 s | 2 s |
GVfs (PTP) | 38 s | 2 s |
GVfs (MTP) | 37 s | Doesn't work |
Go-mtpfs | I/O errors | 10 s |
jmtpfs | Doesn't work | 35 s |
MTPfs | Doesn't work | Doesn't work |
It really appears to be a messy business overall. Hardware support varies, mounting often takes several attempts before it works, plugging/unplugging the cable is often needed, there are I/O errors when listing files, some of which undetected, and I didn't even get to the point of writing anything. We may still be at a stage where it's just better to use SD Cards to exchange data between devices or simply use a cloud service to do so over the network.