Embracing simple-mtpfs as the true MTP tool
(last time edited: 2021-10-16)
tags: mtp, storage, smartphones
The Media Transfer Protocol (MTP) is an extension to the Picture Transfer Protocol (PTP) communications protocol that allows media files to be transferred automatically to and from portable devices. Whereas PTP was designed for downloading photographs from digital cameras, Media Transfer Protocol allows the transfer of music files on digital audio players and media files on portable media players, as well as personal information on personal digital assistants. MTP is a key part of WMDRM10-PD, a digital rights management (DRM) service for the Windows Media platform. In 2011, it became the standard method to transfer files from/to Android.
Ok good, now that we know what MTP stands for.
Anyways, I have used a lot android-file-transfer-linux for years. It's a nice little user friendly graphical tool that simplifies transferring files to your smartphone. Never got into troubles until now.
timeout reaping usb urb
Anyways, I did fix that problem by enabling Developer Mode in my smartphone and enabling USB Debugging.
This program also needs to be executed as root to access the smartphone. We do not want that!
Why not go a little more simpler and secure and flip the finger to android-file-transfer? Who needs graphical interfaces anyways?
simple-mtpfs (Simple Media Transfer Protocol FileSystem) is a file system for Linux (and other operating systems with a FUSE implementation, such as Mac OS X or FreeBSD) capable of operating on files on MTP devices attached via USB to local machine.
simple-mtpfs is a really really simple command-line program that would let you temporarily mount your smartphone as a normal user in a directory so you can transfer your files without hassle.
First of all make sure to disable all developer mode options in your smartphone, including USB Debugging. We do not need that.
As root create udev rules. We are real men, we don't use systemd.
# touch /usr/lib/udev/rules.d/51-android.rules
And add the rules found here.
In Void Linux is not necessary to add these rules manually or create the adbusers group manually.
You can just do.
# xbps-install android-udev-rules
And XBPS will add the rules file and create the group automatically.
Now add your user to the adbusers group.
# groupadd adbusers (just in case)
# usermod -G adbusers -a your_user
Re-login to your shell session and reload udev rules as root.
# udevadm control --reload-rules
Create a temporal directory to mount your smartphone. Notice! Do not create this directory as root! Do it as normal user.
$ mkdir /path/to/androiddir
List connected devices.
$ simple-mtpfs -l
Mount your device, we do not need root. A normal user can handle the FUSE filesystem mounting thanks to the udev rules. Replace $NUMBER with the device number found in the previous command.
$ simple-mtpfs --device <device-number> /path/to/androiddir
If you wanna get more information just add the verbose argument
-v. But the simple-mtpfs program won't be forked to the background.
$ simple-mtpfs -v --device <device-number> /path/to/androiddir
Unmount your device.
$ fusermount -u /path/to/androiddir
There are multiple tools to debug correctly.
lsusbcomes in usbutils package.
udevadmto monitor and restart the udev rules.
mtp-detectthat comes installed with libmtp library as a dependency for simple-mtpfs. Sometimes included in a package called
libmtp-examples. This varies between Linux distributions.
That's all folks.