Saturday, February 21, 2015

Dealing with Android MTP devices in Linux

A couple of frustrating errors you might see when trying to exchange files with your Android phone:

"-1: Unspecified error."

My personal favorite when copying a file to or from the device, the "-6: Not Supported."

Try using jmtpfs.  From Ubuntu/Mint, it is a simple install with "sudo apt-get install jmtpfs".

It isn't perfect, but better than the "native" MTP transfer provided by libmtp, which is clearly broken in Linux and has been for some time. There is no other explanation, as there are several other MTP solutions which according to the Arch Wiki, "...aim at better functionality and performance over libmtp."

Using jmtpfs is pretty simple, just create a directory to use as a mount point, then use jmtpfs to mount your device at that directory.  You can then use the command line or a file manager to navigate to that folder and copy files to/from it.

Other usage patterns can be found in the jmtpfs readme.

I still got an error while trying to overwrite an existing file, so as I said this solution isn't perfect, but it works better than libmtp with my Moto G.  Here is an example of mounting the device to a directory called "mnt":

Removed demonstration gist, but you can view it here if you are interested.

Update 28-Feb-2015:
After more use, I found that jmtpfs is useful for one or two files, but if you need to transfer, say, all of your phone data to your computer as a backup, it was not reliable.  I found the go-mtpfs solution to work very well.  Initially I was not very excited about this solution because it required installing another language (Google's "Go") and some usb libraries, BUT -- the author has kindly provided (or linked to) compiled binaries, which eliminate these worries!

All you need to do is download the binary for your environment.  In my case I chose go-mtpfs.x86_64.

Make the binary executable and test it to see if it runs:

Then plug in your phone and mount it:

That's it!  You should see your phone mounted at ~/phone.  Now you can use Nautilus or whatever to copy and move files.  The author warns that renaming between directories isn't implemented, and you may not see updates to the filesystem done by the phone.  These concerns are minor for what I'm after.

To unmount the phone, do:

Works very reliably.  I just transferred 2GB of data without an issue.

No comments:

Post a Comment