Like it!

Join me on Facebook!

Like it!

Android to Debian/Linux file transfer via MTP

A painless tutorial on how to share files from and to your Android device.

MTP stands for Media Transfer Protocol, a communication protocol used for moving files across portable devices. I never had the luck to make it work under the countless graphical file managers for Linux, so I decided to go the command-line way. For this purpose you will need a couple of small tools.

  • jmtpfs, used for accessing MTP devices. It is based on FUSE, a type of filesystem implemented as a "simple" user program (Unix filesystems are traditionally implemented in the kernel);
  • fusermount, used for mounting and unmounting FUSE filesystems.

Preparing the filesystem

First of all connect via USB the device you want to grab files from. In my case — I'm working with a Nexus 5 phone — I also have to switch it to "file sharing mode", but your mileage may vary.

Choose a directory where you want to temporarily mount your device's filesystem. You can use /mnt, or create a temporary directory in your home, like that:

mkdir ~/android_mount

Then invoke jmtpfs, so that it can mount to that directory the first MTP device it finds:

jmtpfs ~/android_mount

If everything goes well you should see some information on your device, plus a device detection message. In my case I had the following:

Device 0 (VID=18d1 and PID=4ee1) is a Google Inc (for LG Electronics/Samsung) Nexus 4/5/7/10 (MTP).
Android device detected, assigning default bug flags

That's a good sign.

Browsing and unmounting

Now that the device filesystem is properly mounted, cd to your temporary directory (that is ~/android_mount) and do your stuff. Once you're done, you have to unmount the filesystem. Using fusermount the operation is straightforward:

fusermount -u ~/android_mount

Additional notes

For some obscure reason if I mount my device to any folder created under the /tmp directory (e.g. /tmp/android_mount), I am not able to browse it. What I get is the following error message:

fuse: bad mount point `android/': Input/output error

Simple solution in case you are facing this issue: just create your mount directory anywhere else.

Sources

Wikipedia - Media Transfer Protocol (link)
Wikipedia - Filesystem in Userspace (link)
Unix StackExchange - What are the benefits and downsides to use FuseFS filesystems? (link)
Manpages - Fusermount (link)

comments
Yuber Vasquez on April 10, 2018 at 20:51
Good post, thanks you
Yuber Vasquez on April 21, 2018 at 05:15
Hi, i use jmptfs ~/android_mount but a simple ls command take too long time, long and very long time.
Can you help me please how i can reduce this time?
thanks
Triangles on May 22, 2018 at 19:11
@Yuber Vasquez no idea, sorry! ls command runs pretty smooth on my environment, there could be many factors at play here...