Difference between revisions of "Media Transfer Protocol"

From ArchWiki
Jump to: navigation, search
(Using media players: needed for my Nexus 7)
(FUSE filesystems: change note to be more accurate and objective, simple-mtpfs just worked fine for me while AFT failed)
 
(216 intermediate revisions by 67 users not shown)
Line 1: Line 1:
[[Category:Sound]]
+
[[Category:Storage]]
MTP is the "Media Transfer Protocol" and is used by many mp3 players (e.g. Creative Zen) and mobile phones (e.g. Android 3+ devices). It is part of the "Windows Media" Framework and has close relationship with Windows Media Player.
+
[[Category:Mobile devices]]
 +
[[fa:MTP]]
 +
[[ja:MTP]]
 +
[[ru:MTP]]
 +
[[zh-hans:MTP]]
 +
{{Related articles start}}
 +
{{Related|Android#Transferring files}}
 +
{{Related|USB storage devices}}
 +
{{Related articles end}}
 +
The [[Wikipedia:Media Transfer Protocol|Media Transfer Protocol]] (MTP) can be used to transfer media files to and from many mobile phones (all Windows Phone 7/8/10 devices, most newer [[Android]] devices) and media players (e.g. Creative Zen).
  
==Installation==
+
== Connecting ==
MTP support is provided by [http://libmtp.sourceforge.net/ libmtp], [[pacman|installable]] with the {{Pkg|libmtp}} package from the [[official repositories]].
 
  
==Usage==
+
To connect your computer to a device via MTP:
After installation, you have several MTP tools available.
 
Upon connecting your MTP device, you use:
 
# mtp-detect
 
to see if your MTP device is detected.
 
  
To connect to your MTP device, you use:
+
* the device needs to be connected to your computer via USB
# mtp-connect
+
* MTP needs to be enabled on the device
 +
* the device's screen needs to be unlocked (for security reasons)
  
If connection is successful, you will be given several switch options in conjunction with {{ic|mtp-connect}} to access data on the device.
+
== FUSE filesystems ==
  
There are also several stand alone commands you can use to access your MTP device such as,
+
The following programs let you access MTP devices via a [[FUSE]] filesystem:
{{Warning | Some commands may be harmful to your MTP device!!! }}
 
  
  mtp-albumart        mtp-emptyfolders    mtp-getplaylist    mtp-reset          mtp-trexist
+
* {{App|[[#Android File Transfer]]|MTP client with CLI, Qt UI, and FUSE wrapper; uses custom MTP implementation|https://whoozle.github.io/android-file-transfer-linux/|{{Pkg|android-file-transfer}}}}
  mtp-albums          mtp-files          mtp-hotplug        mtp-sendfile
+
* {{App|[[#go-mtpfs]]|FUSE filesystem with custom MTP implementation, written in Go|https://github.com/hanwen/go-mtpfs|{{AUR|go-mtpfs-git}}}}
  mtp-connect        mtp-folders        mtp-newfolder      mtp-sendtr
+
* [[#libmtp]] based FUSE filesystems:
  mtp-delfile        mtp-format          mtp-newplaylist    mtp-thumb
+
** [[#mtpfs]], {{Pkg|mtpfs}}, https://www.adebenham.com/mtpfs/
  mtp-detect          mtp-getfile        mtp-playlists      mtp-tracks
+
** [[#jmtpfs]], {{AUR|jmtpfs}}, https://github.com/JasonFerrara/jmtpfs
 +
** [[#simple-mtpfs]], {{AUR|simple-mtpfs}}, https://github.com/phatina/simple-mtpfs/
  
==Using media players==
+
{{Note|MTP is messy and its implementation varies between devices. Try the above clients to see which one works best with your device.}}
You can also use your MTP device in music players such as Amarok. To do this you may have to edit {{ic|/etc/udev/rules.d/51-android.rules}} (the MTP device used in the following example is a Galaxy Nexus):
+
 
To do this run:
+
{{Tip|It is recommended to reboot your computer after installing MTP related packages.}}
$ lsusb
+
 
and look for your device, it will be something like:
+
For the FUSE-based file systems, you might need to create the mount-point directory first. The directory {{ic|~/mnt}} is used as an example below.
Bus 003 Device 011: ID 04e8:6860 Samsung Electronics Co., Ltd GT-I9100 Phone [Galaxy S II], GT-P7500 [Galaxy Tab 10.1]
+
 
in which case the entry would be:
+
FUSE mounts can generally be unmounted using {{ic|fusermount -u ''mountpoint''}}.
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666", OWNER="[username]"
 
Then, reload udev rules:
 
# udevadm control --reload
 
  
{{Note|After installing MTP you may have to reboot for your device to be recognised}}
+
=== mtpfs ===
  
==mtpfs==
+
{{Note | The following is likely to not work and you might have to resort to [[Digital_Cameras#libgphoto2|gphoto2]] or a file manager with gvfs support like [[PCManFM]]. }}
Mtpfs is FUSE filesystem that supports reading and writing from any MTP device. Basically it allows you to mount your device as an external drive.
 
  
Mtpfs can be installed with the packge {{Pkg|mtpfs}}, available from the [[official repositories]].
+
First edit your {{ic|/etc/fuse.conf}} and uncomment the following line:
*First edit your {{ic|/etc/fuse.conf}} and uncomment the following line:
 
 
  user_allow_other
 
  user_allow_other
  
*To mount your device  
+
Mount your device on {{ic|~/mnt}}:
  $ mtpfs -o allow_other /media/YOURMOUNTPOINT
+
  $ mtpfs -o allow_other ~/mnt
*To unmount your device
+
 
  $ fusermount -u /media/YOURMOUNTPOINT
+
=== jmtpfs ===
*To unmount your device as root
+
 
  # umount /media/YOURMOUNTPOINT
+
Mount device on {{ic|~/mnt}}:
 +
 
 +
$ jmtpfs ~/mnt
 +
 
 +
Make this cohere to the rest of Linux (use regular mount/umount commands) by doing two steps
 +
 
 +
$# ln -s <actual mount command's path/name>  <a name consistent with Linux's mount convention>
 +
$  ln -s /sbin/jmtpfs                        /sbin/mount.jmtpfs
 +
 
 +
add this line to /etc/fstab;
 +
 
 +
  #jmtpfs <mount path>        fuse nodev,allow_other,<other options>                            0    0
 +
  jmtpfs /home/sam/run/motog fuse nodev,allow_other,rw,user,noauto,noatime,uid=1000,gid=1000    0    0
 +
 
 +
Now mount the device and see if the options "took"
 +
 
 +
  $ mount /home/sam/run/motog
 +
  Device 0 (VID=22b8 and PID=2e82) is a Motorola Moto G (ID2).
 +
  Android device detected, assigning default bug flags
 +
  $ mount
 +
  ...
 +
  jmtpfs on /home/sam/run/motog type fuse.jmtpfs (rw,nosuid,nodev,noexec,noatime,user_id=1000,group_id=1000,allow_other,user=sam)
 +
 
 +
=== simple-mtpfs ===
 +
 
 +
Run {{ic|simple-mtpfs -l}} to list detected devices.
 +
 
 +
To mount the first device in the list to {{ic|~/mnt}}, run {{ic|simple-mtpfs --device 1 ~/mnt}}.
 +
 
 +
=== go-mtpfs ===
 +
 
 +
{{Note|Mounting with {{ic|go-mtpfs}} might fail if an external SD Card is present. If you try to access your device while having an SD card and go-mtpfs complains, try removing the SD card and mounting again.}}
 +
 
 +
Install {{Pkg|android-udev}}, which will allow you to edit {{ic|/etc/udev/rules.d/51-android.rules}} and apply to your {{ic|idVendor}} and {{ic|idProduct}}, which you can see after running ''mtp-detect''. To the end of the line, add your user {{ic|<nowiki>OWNER="<user>"</nowiki>}}.
 +
 
 +
Mount device on {{ic|~/mnt}}:
 +
 
 +
$ go-mtpfs ~/mnt
 +
 
 +
{{Note|When using multiple devices you may want to use the {{ic|-d}} flag to specify a device (id can be found by running {{ic|mtp-detect}})}}
 +
 
 +
=== Android File Transfer ===
 +
 
 +
;FUSE interface
 +
 
 +
Mount your device on {{ic|~/my-device}}:
 +
$ mkdir ~/my-device
 +
  $ aft-mtp-mount ~/my-device
 +
 
 +
If you want album art to be displayed, it must be named {{ic|albumart.xxx}} and placed first in the destination folder. Then copy other files. Also, note that fuse could be 7-8 times slower than ui/cli file transfer.
 +
 
 +
;Qt user interface
 +
 
 +
Start the application, choose a destination folder and click any button on the toolbar. Available options are: ''Upload Album'', ''Upload Directory'' and ''Upload Files''. The latter two are self-explanatory. ''Upload album'' searches the source directory for album covers, and sets the best available cover.
 +
 
 +
== libmtp ==
 +
 
 +
[http://libmtp.sourceforge.net/ libmtp] is a library MTP implementation, which also comes with some example command-line tools (which you can list using {{ic|pacman -Ql libmtp}}).
 +
 
 +
[[Install]] the {{Pkg|libmtp}} package.
 +
 
 +
Run {{ic|mtp-detect}} to detect your device.
 +
 
 +
If an error is returned, make sure your user is in the see {{ic|uucp}} [[group]].
 +
 
 +
You can transfer files using the {{ic|mtp-connect}} command.
 +
 
 +
== Media players ==
 +
 
 +
You can also use your MTP device in music players such as [[Amarok]]. To achieve this, you might have to edit {{ic|/etc/udev/rules.d/51-android.rules}} (the MTP device used in the following example is a Galaxy Nexus).
 +
Run:
 +
 
 +
$ lsusb
 +
 
 +
Search for your device. It should be something like that:
 +
  Bus 003 Device 011: ID 04e8:6860 Samsung Electronics Co., Ltd GT-I9100 Phone [Galaxy S II], GT-P7500 [Galaxy Tab 10.1]
 +
 
 +
And entry to {{ic|/etc/udev/rules.d/51-android.rules}} will be this:
 +
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666", OWNER="[username]"
 +
 
 +
Also reload udev rules:
 +
# udevadm control --reload
  
Also, you can put them into your ~/.bashrc:
+
== File manager integration ==
alias android-connect="mtpfs -o allow_other /media/YOURMOUNTPOINT"
 
alias android-disconnect="fusermount -u /media/YOURMOUNTPOINT"
 
Or, with sudo
 
alias android-disconnect="sudo umount -u /media/YOURMOUNTPOINT"
 
{{Note|if you want not be asked for password when using sudo, please refer to [[USB Storage Devices#Mounting USB devices]]}}
 
  
==jmtpfs==
+
To view the contents of your Android device's storage via MTP in your file manager, install the corresponding plugin:
[http://research.jacquette.com/jmtpfs-exchanging-files-between-android-devices-and-linux/ jmtpfs] is a FUSE and libmtp based filesystem for accessing MTP (Media Transfer Protocol) devices. It was specifically designed for exchanging files between Linux systems and newer Android devices that support MTP but not USB Mass Storage.
 
jmtpfs is available as {{aur|jmtpfs}} in the [[AUR]].
 
  
Use these commands to mount and unmount your device :
+
* For file managers that use [[GVFS]] (GNOME Files), install {{Pkg|gvfs-mtp}} for MTP or {{Pkg|gvfs-gphoto2}} for PTP support.
$ jmtpfs ~/mtp
+
* For file managers that use KIO (KDE's Dolphin), MTP support is included in {{Pkg|kio-extras}} (dependency of dolphin).
  
$ fusermount -u ~/mtp
+
After installing the required package, the device should show up in the file manager automatically and be accessible via an URL, for example {{ic|mtp://[usb:002,013]/}}.
  
==go-mtpfs==
+
=== gvfs-mtp ===
{{Note|Go-mtpfs gives a better performance while writing files to some devices than mtpfs/jmtpfs. Try it if you have slow speeds.}}
 
If the above instructions don't show any positive results one should try {{aur|go-mtpfs-git}} from the [[AUR]].
 
The following has been tested on a Samsung Galaxy Nexus GSM and Samsung Galaxy S 3 mini.
 
  
If you want do it simpler, install {{Pkg|go}}, {{Pkg|libmtp}} and {{Pkg|git}} from the [[official repositories]]. After that install {{AUR|go-mtpfs-git}} from the [[AUR]].
+
{{Merge|udev}}
  
 +
The {{Pkg|gvfs-mtp}} is available in the official repositories.
  
As in the section above install {{aur|android-udev}} which will provide you with "/etc/udev/rules.d/51-android.rules" edit it to apply to
+
With {{ic|lsusb}} you can get information about your device where Bus and Device numbers can be used with {{ic|gvfs-mtp}} and device ID for creating of an [[udev]] rule.
your vendorID and productID, which you can see after running mtp-detect. To the end of the line add with a comma OWNER="yourusername". Save the file.
+
Bus '''002''' Device '''018''': ID '''04b7''':'''88a9''' Compal Electronics, Inc.
 +
(...)
  
*Add yourself to the "fuse" group:
+
To see detected device with enabled MTP
gpasswd -a [user] fuse
 
  
*If the group "fuse" doesn't exist create it with:
+
Use ''gvfs-mount'':
groupadd fuse
 
  
Logout or reboot to apply these changes.
+
{{hc|<NOWIKI>gvfs-mount -li | grep -e ^Volume -e activation_root</NOWIKI>|2=
 +
Volume(0): MT65xx Android Phone
 +
  activation_root=mtp://[usb:'''002''','''018''']/
 +
}}
  
*To create a mount point called "Android" issue the following commands:
+
Use ''lsusb'':
mkdir Android
 
  
*To mount your phone use:
+
{{hc|<NOWIKI>lsusb -v 2> /dev/null | grep -e Bus -e iInterface -e bInterfaceProtocol</NOWIKI>|
go-mtpfs Android
+
(......
 +
......)
 +
Bus 002 Device 018: ID 04b7:88a9 Compal Electronics, Inc.
 +
      bInterfaceProtocol      0
 +
      iInterface              5 MTP
 +
(......
 +
......)
 +
}}
  
*To unmount your phone:
+
To mount all available connected MTP devices use inline script
fusermount -u Android
 
  
You can create a .bashrc alias as in the example above for easier use.
+
gvfs-mount -li | awk -F= '{if(index($2,"mtp") == 1)system("gvfs-mount "$2)}'
  
==gvfs-mtp==
+
To mount or dismount from a command with gvfs-mtp use Bus and Device numbers, e.g. to mount {{ic|gvfs-mount mtp://[usb:001,007]/}} and to unmount {{ic|gvfs-mount -u mtp://[usb:001,007]/}}. The mounted device will be available in a directory that begins with ''mtp:host='' and is located under ''/run/user/$UID/gvfs/''.
  
Philip Langdale is has implemented native MTP support for gvfs. The weaknesses of gphoto2 and mtpfs are listed in his [http://intr.overt.org/blog/?p=153 blog post].
+
Disable automount of MTP devises with gvfs you will need to change value ''true'' to ''false'' for variable ''AutoMount'' that is located in {{ic|/usr/share/gvfs/mounts/mtp.mount}}.
*The native mtp implementation for gvfs [https://bugzilla.gnome.org/show_bug.cgi?id=666195 has been merged upstream] and has been released in gvfs [http://git.gnome.org/browse/gvfs/commit/?id=d6c8e3a4910ee2c5968886328ebe9456b445796b 1.15.2].
 
* You can grab the stable gvfs-mtp package from extra. You may want to reboot your PC to make it actually working.
 
  
*Devices will have gvfs paths like this
+
{{Note|The file managers can have own options for automount. On start they checking for all available mountable devices.}}
gvfs-ls mtp://[usb:002,013]/
 
  
==simple-mtpfs==
+
If your device isn't showing up in the file manager then [[#libmtp]] is missing a native support and is not currently available in the list of the [https://sourceforge.net/p/libmtp/code/ci/HEAD/tree/src/music-players.h supported devices]. If you will try to mount by using command line you may also get an error
  
This is another FUSE filesystem for MTP devices. You may find this to be more reliable than {{Pkg|mtpfs}}. {{aur|simple-mtpfs}} is available in the AUR or can be built from source. Remember '''do not''' run the following commands as root.
+
{{bc|1=Device 0 (VID=''XXXX'' and PID=''XXXX'') is UNKNOWN.
 +
Please report this VID/PID and the device model to the libmtp development team}}
  
* To list MTP devices run
+
The workaround to make it shown in the file manager is to write an [[udev]] rule for the device but it is no guaranty that you will be able to mount it with by using MTP connection.
  simple-mtpfs --list-devices
 
  
* To mount a MTP devices (in this example device 0) run
+
Use ID number that represents by pattern '''vendorId''':'''productID''',e.g. '''04b7''':'''88a9''', and make an udev rule by creating a configuration file
simple-mtpfs /path/to/your/mount/point
 
  
* To un mount run
+
{{hc|/etc/udev/rules.d/51-android.rules|<NOWIKI>
  fusermount -u /path/to/your/mount/point
+
SUBSYSTEM=="usb", ATTR{idVendor}=="04b7", ATTR{idProduct}=="88a9", MODE="0660", GROUP="uucp", ENV{ID_MTP_DEVICE}="1", SYMLINK+="libmtp"</NOWIKI>
 +
}}
 +
Reload the udev rules.
  
==KDE MTP KIO Slave==
+
# udevadm control --reload
There is a MTP KIO Slave built upon libmtp availiable as package {{Pkg|kio-mtp}}.
 
  
Using KIO makes file access in KDE seamless, in principle any KDE application would be able read/write files on the device.
+
The file managers with support for [[gvfs]] will be able to show MTP devices and mount them if supported by [[#libmtp]] but if has no support and cannot be opened then change settings in the phone to PTP and install {{Pkg|gvfs-gphoto2}} for having access at least to the photos, command line mounting of PTP is a little similar to mounting of the MTP devices: {{ic|gvfs-mount gphoto2://[usb:002,019]/}}.
  
===Usage===
+
{{Note|If you getting limited access to the device and cannot use standard commands from command line such as e.g. {{ic|cp}},{{ic|ls}} then look for [[gvfs]] own alternatives, {{ic|ls -1 /usr/bin/gvfs-*}}.}}
The device will be available under the path mtp:/
 
  
===Workaround if the KDE device actions doesn't work===
+
== Troubleshooting ==
If you are not able to use the action "Open with File Manager", you may work around this problem by editing the file /usr/share/apps/solid/actions/solid_mtp.desktop
 
  
Change the line
+
=== jmtpfs: Input/output error upon first access ===
Exec=kioclient exec mtp:udi=%i/
 
To
 
Exec=dolphin "mtp:/"
 
  
==GNOME gMTP==
+
Symptoms: jmtpfs successfully mounts, but as soon as one attempts to access files on the device (e.g. via {{ic|ls}}), an error is reported:
gMTP is a native Gnome application used for MTP access.
 
  
{{aur|gmtp}} is currently located in the [[AUR]] .
+
  cannot access <mount-point>: Input/output error
  
==Workarounds for Android==
+
This appears to be a security feature: MTP does not work when the phone is locked by the lockscreen. Unlock the phone and it should work again as long as the cord remains connected.
* HTC Phones automatically enter usb debugging mode on usb connect. Manually turn it off once connected to give libmtp access to the device.
 
  
MTP is still buggy and may crash despite the best efforts of developers. The following are alternatives:
+
=== kio-mtp: cannot use "Open with File Manager" action ===
* AirDroid - an Android app to access files via your web browser.
 
* FTP client on Android - If you run a local FTP server on Arch (such as [[Vsftp]]), there are many FTP clients available on the Play Store which will give read/ write access to your device's files.
 
* FTP Server on Android. Note: since FTP client using passive transfer (server connect to client) do not forget to disable firewall or adding rules for allowing FTP server connect to your PC.
 
** Ftp Server (by The Olive Tree) app in Play Store acts as FTP server on Android and allows RW access to pretty much all your storage.
 
*** Pro: Doesn't require root and just works!
 
*** Cons: Doesn't work with tethering network.
 
** FTPServer (by Andreas Liebig) - Just work.
 
* SSH server on Android.
 
** For example, SSHelper, available on the Play Store, just works without requiring root access. Assuming SSHelper is listening on port 20 and the phone's IP address is 192.168.0.20, the following command will synchronise a local directory with the external SD card of the Android device:
 
  rsync --rsh="ssh -p 20" --modify-window=1  ~/local_files  192.168.0.20:/mnt/extSdCard/remote_files
 
Note the {{ic|--modify-window}} option, which is often used when rsyncing to a FAT filesystem (such as the one used by Android devices for their internal memory and external SD cards).
 
* Samba - an Android app to share your SD card as a windows fileshare. Pros: Your desktop apps work as before (since the SD card appears as a windows fileshare). Cons: you need to root your phone.
 
  
==Security features on android==
+
If you are not able to use the action "Open with File Manager", you may work around this problem by editing the file {{ic|/usr/share/solid/actions/solid_mtp.desktop}}.
If you use android 4.x please unlock phone (screen unlock) and then connect phone to USB.
 
  
If you not unlock you have in KDE "No Storages found. Maybe you need to unlock your device?" or error 02fe in console.
+
Change the line {{ic|1=Exec=kioclient exec mtp:udi=%i/}} to {{ic|1=Exec=dolphin "mtp:/"}}.

Latest revision as of 19:13, 18 May 2018

The Media Transfer Protocol (MTP) can be used to transfer media files to and from many mobile phones (all Windows Phone 7/8/10 devices, most newer Android devices) and media players (e.g. Creative Zen).

Connecting

To connect your computer to a device via MTP:

  • the device needs to be connected to your computer via USB
  • MTP needs to be enabled on the device
  • the device's screen needs to be unlocked (for security reasons)

FUSE filesystems

The following programs let you access MTP devices via a FUSE filesystem:

https://whoozle.github.io/android-file-transfer-linux/ || android-file-transfer
  • #go-mtpfs — FUSE filesystem with custom MTP implementation, written in Go
https://github.com/hanwen/go-mtpfs || go-mtpfs-gitAUR
Note: MTP is messy and its implementation varies between devices. Try the above clients to see which one works best with your device.
Tip: It is recommended to reboot your computer after installing MTP related packages.

For the FUSE-based file systems, you might need to create the mount-point directory first. The directory ~/mnt is used as an example below.

FUSE mounts can generally be unmounted using fusermount -u mountpoint.

mtpfs

Note: The following is likely to not work and you might have to resort to gphoto2 or a file manager with gvfs support like PCManFM.

First edit your /etc/fuse.conf and uncomment the following line:

user_allow_other

Mount your device on ~/mnt:

$ mtpfs -o allow_other ~/mnt

jmtpfs

Mount device on ~/mnt:

$ jmtpfs ~/mnt

Make this cohere to the rest of Linux (use regular mount/umount commands) by doing two steps

$# ln -s <actual mount command's path/name>  <a name consistent with Linux's mount convention>
$  ln -s /sbin/jmtpfs                        /sbin/mount.jmtpfs

add this line to /etc/fstab;

 #jmtpfs <mount path>        fuse nodev,allow_other,<other options>                             0    0
  jmtpfs /home/sam/run/motog fuse nodev,allow_other,rw,user,noauto,noatime,uid=1000,gid=1000    0    0

Now mount the device and see if the options "took"

 $ mount /home/sam/run/motog
 Device 0 (VID=22b8 and PID=2e82) is a Motorola Moto G (ID2).
 Android device detected, assigning default bug flags
 $ mount 
  ...
  jmtpfs on /home/sam/run/motog type fuse.jmtpfs (rw,nosuid,nodev,noexec,noatime,user_id=1000,group_id=1000,allow_other,user=sam)

simple-mtpfs

Run simple-mtpfs -l to list detected devices.

To mount the first device in the list to ~/mnt, run simple-mtpfs --device 1 ~/mnt.

go-mtpfs

Note: Mounting with go-mtpfs might fail if an external SD Card is present. If you try to access your device while having an SD card and go-mtpfs complains, try removing the SD card and mounting again.

Install android-udev, which will allow you to edit /etc/udev/rules.d/51-android.rules and apply to your idVendor and idProduct, which you can see after running mtp-detect. To the end of the line, add your user OWNER="<user>".

Mount device on ~/mnt:

$ go-mtpfs ~/mnt
Note: When using multiple devices you may want to use the -d flag to specify a device (id can be found by running mtp-detect)

Android File Transfer

FUSE interface

Mount your device on ~/my-device:

$ mkdir ~/my-device
$ aft-mtp-mount ~/my-device

If you want album art to be displayed, it must be named albumart.xxx and placed first in the destination folder. Then copy other files. Also, note that fuse could be 7-8 times slower than ui/cli file transfer.

Qt user interface

Start the application, choose a destination folder and click any button on the toolbar. Available options are: Upload Album, Upload Directory and Upload Files. The latter two are self-explanatory. Upload album searches the source directory for album covers, and sets the best available cover.

libmtp

libmtp is a library MTP implementation, which also comes with some example command-line tools (which you can list using pacman -Ql libmtp).

Install the libmtp package.

Run mtp-detect to detect your device.

If an error is returned, make sure your user is in the see uucp group.

You can transfer files using the mtp-connect command.

Media players

You can also use your MTP device in music players such as Amarok. To achieve this, you might have to edit /etc/udev/rules.d/51-android.rules (the MTP device used in the following example is a Galaxy Nexus). Run:

$ lsusb

Search for your device. It should be something like that:

Bus 003 Device 011: ID 04e8:6860 Samsung Electronics Co., Ltd GT-I9100 Phone [Galaxy S II], GT-P7500 [Galaxy Tab 10.1]

And entry to /etc/udev/rules.d/51-android.rules will be this:

SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666", OWNER="[username]"

Also reload udev rules:

# udevadm control --reload

File manager integration

To view the contents of your Android device's storage via MTP in your file manager, install the corresponding plugin:

  • For file managers that use GVFS (GNOME Files), install gvfs-mtp for MTP or gvfs-gphoto2 for PTP support.
  • For file managers that use KIO (KDE's Dolphin), MTP support is included in kio-extras (dependency of dolphin).

After installing the required package, the device should show up in the file manager automatically and be accessible via an URL, for example mtp://[usb:002,013]/.

gvfs-mtp

Merge-arrows-2.pngThis article or section is a candidate for merging with udev.Merge-arrows-2.png

Notes: please use the second argument of the template to provide more detailed indications. (Discuss in Talk:Media Transfer Protocol#)

The gvfs-mtp is available in the official repositories.

With lsusb you can get information about your device where Bus and Device numbers can be used with gvfs-mtp and device ID for creating of an udev rule.

Bus 002 Device 018: ID 04b7:88a9 Compal Electronics, Inc.
(...)

To see detected device with enabled MTP

Use gvfs-mount:

gvfs-mount -li | grep -e ^Volume -e activation_root
Volume(0): MT65xx Android Phone
  activation_root=mtp://[usb:002,018]/

Use lsusb:

lsusb -v 2> /dev/null | grep -e Bus -e iInterface -e bInterfaceProtocol
(......
......)
Bus 002 Device 018: ID 04b7:88a9 Compal Electronics, Inc. 
      bInterfaceProtocol      0 
      iInterface              5 MTP
(......
......)

To mount all available connected MTP devices use inline script

gvfs-mount -li | awk -F= '{if(index($2,"mtp") == 1)system("gvfs-mount "$2)}'

To mount or dismount from a command with gvfs-mtp use Bus and Device numbers, e.g. to mount gvfs-mount mtp://[usb:001,007]/ and to unmount gvfs-mount -u mtp://[usb:001,007]/. The mounted device will be available in a directory that begins with mtp:host= and is located under /run/user/$UID/gvfs/.

Disable automount of MTP devises with gvfs you will need to change value true to false for variable AutoMount that is located in /usr/share/gvfs/mounts/mtp.mount.

Note: The file managers can have own options for automount. On start they checking for all available mountable devices.

If your device isn't showing up in the file manager then #libmtp is missing a native support and is not currently available in the list of the supported devices. If you will try to mount by using command line you may also get an error

Device 0 (VID=XXXX and PID=XXXX) is UNKNOWN.
Please report this VID/PID and the device model to the libmtp development team

The workaround to make it shown in the file manager is to write an udev rule for the device but it is no guaranty that you will be able to mount it with by using MTP connection.

Use ID number that represents by pattern vendorId:productID,e.g. 04b7:88a9, and make an udev rule by creating a configuration file

/etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="04b7", ATTR{idProduct}=="88a9", MODE="0660", GROUP="uucp", ENV{ID_MTP_DEVICE}="1", SYMLINK+="libmtp"

Reload the udev rules.

# udevadm control --reload

The file managers with support for gvfs will be able to show MTP devices and mount them if supported by #libmtp but if has no support and cannot be opened then change settings in the phone to PTP and install gvfs-gphoto2 for having access at least to the photos, command line mounting of PTP is a little similar to mounting of the MTP devices: gvfs-mount gphoto2://[usb:002,019]/.

Note: If you getting limited access to the device and cannot use standard commands from command line such as e.g. cp,ls then look for gvfs own alternatives, ls -1 /usr/bin/gvfs-*.

Troubleshooting

jmtpfs: Input/output error upon first access

Symptoms: jmtpfs successfully mounts, but as soon as one attempts to access files on the device (e.g. via ls), an error is reported:

 cannot access <mount-point>: Input/output error

This appears to be a security feature: MTP does not work when the phone is locked by the lockscreen. Unlock the phone and it should work again as long as the cord remains connected.

kio-mtp: cannot use "Open with File Manager" action

If you are not able to use the action "Open with File Manager", you may work around this problem by editing the file /usr/share/solid/actions/solid_mtp.desktop.

Change the line Exec=kioclient exec mtp:udi=%i/ to Exec=dolphin "mtp:/".