Transferring media files from smartphone via MTP

Compared to my old Samsung Galaxy Player (Android 2.3, Gingerbread), transferring files between my laptop/PC and my newer Android devices is always more cumbersome. Ever since Android 3, the protocol used for file transfer is no longer USB Mass Storage, but MTP.

Arguably MTP has its advantages, but the effect to me as a Linux user is still pain. I’ve tried various things to no avail, from jmtpfs (always input/output error) to gvfs-backends (Nautilus et al always sees the device as empty). Usually I ended up using Bluetooth, even Google Drive/Dropbox or Whatsapp/BBM.

libmtp/mtp-tools usually works, but the CLI commands are not very user-friendly. First, the manpages are nonexistent/incomplete. Even when given -h or some wrong option, the commands like mtp-getfile or mtp-sendfile will invariably hang for many seconds trying to detect the connected device each time they are run, before reporting the error in argument/option.

I wrote App-MTPUtils which contains several wrapper scripts to lessen my pain when using libmtp. Suppose you want to get several files from your phone. First, you run:

% mtp-files > mtp-files.out

(This might be done automatically in the future.)

After that, you can list the files using:

% mtputils-list-files -l
% mtputils-list-files '*.mp4' -l

For me this is more readable as the output is a table and more ls-like.

To get your files, you can specify their ID’s or filenames as arguments to mtputils-get-files. Compared to mtp-getfile you can get multiple files in one command, and there is a tab completion feature:

% mtputils-get-files VID<tab>

To delete files, there is mtputils-del-files.

Leave a comment