Ubuntu – Copying file from MTP device using libmtp (over USB)

mtpUbuntuusb

Have a current project where I'm trying to figure out a way to copy files(a video) from a MTP device over USB.

From the wiki I discover there is an open-source implementation called libmtp. Has anyone reading this used this? Any examples, tutorials?
I'd prefer to run Ubuntu with MATE.

Unix-like systems
A free and open-source implementation of the Media Transfer Protocol is available as libmtp.This library incorporates product and device IDs from many sources, and is commonly used in other software for MTP support.

Best Answer

You should install the required packages:

sudo apt-get install libmtp-dev mtp-tools mtpfs

Connect your device then run mtp-detect, this command will detect and give you some information about your device.

Run mtp-connect then mtp-folders to display your folders with their ID

the mtp-files will display your files/folders with their ID

to create a list file run:

mtp-files > file_list.txt

Use the command mtp-getfile to copy file from your device to your computer , there is an example from debian wiki:

file_list.txt will now contain entries like this:

File ID: 81
Filename: WP_20161029_16_26_49_Pro.jpg
File size 936160 (0x00000000000E48E0) bytes
Parent ID: 12
Storage ID: 0x00010001
Filetype: JPEG file

where "Parent ID" is something like the folder where the file resides on the smartphone. So you'll want to do something like this to get that particular file:

mkdir "12"
mtp-getfile "81" "12/WP_20161029_16_26_49_Pro.jpg"
Related Question