Media Transfer Protocol: Difference between revisions

From ArchWiki
(→‎gvfs-mtp: replaced with tested updated and working udev rule)
(→‎go-mtpfs: misc style + move last addition as a item in the list in the Template:Note)
 
(111 intermediate revisions by 33 users not shown)
Line 1: Line 1:
[[Category:Storage]]
[[Category:Storage]]
[[Category:Mobile devices]]
[[Category:Mobile devices]]
[[fa:MTP]]
[[de:MTP]]
[[ja:MTP]]
[[ja:MTP]]
[[ru:MTP]]
[[zh-hans:Media Transfer Protocol]]
[[zh-CN:MTP]]
{{Related articles start}}
{{Related articles start}}
{{Related|Android#Transferring files}}
{{Related|USB storage devices}}
{{Related|USB storage devices}}
{{Related articles end}}
{{Related articles end}}
[[Wikipedia:Media_Transfer_Protocol|MTP]], or the ''Media Transfer Protocol'', is a USB device class which is used by many mobile phones (e.g. Samsung Galaxy S4) and media players (e.g. Creative Zen).
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 ==


=== Functionality ===
To connect your computer to a device via MTP:


Linux MTP support is provided by [[installing]] the {{Pkg|libmtp}} package. It can be installed on its own and used to access devices. However, a number of packages are available that use it as a dependency and add additional convenience (e.g. filemanager) functionalities and compatibility with particular device types - which includes improving transfer access speeds.
* 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)


These packages to choose from all implement a [[Wikipedia:Filesystem in Userspace]]:
== FUSE filesystems ==
 
* {{Pkg|mtpfs}}
* {{AUR|jmtpfs}} - is reported to work well for newer Android 4+ devices
* {{AUR|go-mtpfs-git}} - is reported to work well for newer Android 3+ devices
* {{AUR|simple-mtpfs}}
* {{Pkg|android-file-transfer}} - MTP client with minimalistic UI
 
All of them aim at better functionality and performance over {{ic|libmtp}}. Since there are a lot of different USB devices, you might want to research first which one looks most suitable for yours.


The following programs let you access MTP devices via a [[FUSE]] filesystem.
{{Note|MTP is messy and its implementation varies between devices. Try the below clients and see which one works best with your device.}}
{{Tip|It is recommended to reboot your computer after installing MTP related packages.}}
{{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 {{ic|~/mnt}} is used in the examples below.


=== Integration with file managers ===
FUSE mounts can generally be unmounted using {{ic|fusermount -u ''mountpoint''}}.


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


* For file managers that use [[GVFS]] (GNOME Files), install {{Pkg|gvfs-mtp}} for MTP or {{Pkg|gvfs-gphoto2}} for PTP support.
{{App|Android File Transfer|MTP client with CLI, Qt UI, and FUSE wrapper which uses a custom MTP implementation|https://whoozle.github.io/android-file-transfer-linux/|{{Pkg|android-file-transfer}}}}
* For file managers that use KIO (KDE's Dolphin), MTP support is included in {{Pkg|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 {{ic|mtp://[usb:002,013]/}}.
Mount your device on {{ic|~/mnt}}:
$ aft-mtp-mount ~/mnt


== Usage ==
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.
 
It might be required to create a mount-point directory first. The directory {{ic|~/mnt}} is used as an example below. Also do not forget to unlock your phone's screen before connecting it to the computer.
 
=== libmtp ===
 
Detect your device:
 
# mtp-detect
 
If an error is returned, see [[#libmtp 2|troubleshooting libmtp]].
 
{{Note|Your regular user must be in the {{ic|uucp}} [[users_and_groups#Example_adding_a_user|group]].}}


Connect to your device:
If you want to interact with it via the command line interface, run the command:
  # mtp-connect
  $ aft-mtp-cli
Type ''help'' in order to list all the commands available, ''exit'' to quit.


If connection is successful, there are several switch options to use in conjunction with ''mtp-connect'' to access data on the device. You might want to use some stand alone commands:
If you want to interact with it via the graphical user interface, start the ''android-file-transfer'' 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.
  mtp-albumart        mtp-emptyfolders    mtp-getplaylist    mtp-reset          mtp-trexist
  mtp-albums          mtp-files          mtp-hotplug        mtp-sendfile
  mtp-connect        mtp-folders        mtp-newfolder      mtp-sendtr
  mtp-delfile        mtp-format          mtp-newplaylist    mtp-thumb
  mtp-detect          mtp-getfile        mtp-playlists      mtp-tracks


=== 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]]. }}
{{App|MTPfs|based on [[#libmtp|libmtp]], it is a FUSE filesystem that supports reading and writing from any MTP device|https://www.adebenham.com/mtpfs/|{{Pkg|mtpfs}}}}
{{Note | The following is likely to not work and you might have to resort to [[libgphoto2]] or a file manager with gvfs support like [[PCManFM]]. }}


First edit your {{ic|/etc/fuse.conf}} and uncomment the following line:
First edit your {{ic|/etc/fuse.conf}} and uncomment the following line:
Line 71: Line 53:
  $ mtpfs -o allow_other ~/mnt
  $ mtpfs -o allow_other ~/mnt


Unmount device mounted on {{ic|~/mnt}}:
=== jmtpfs ===


$ fusermount -u ~/mnt
{{App|jmtpfs|based on [[#libmtp|libmtp]] for accessing MTP (Media Transfer Protocol) devices|https://github.com/JasonFerrara/jmtpfs|{{AUR|jmtpfs}}}}
 
=== jmtpfs ===


Mount device on {{ic|~/mnt}}:
Mount device on {{ic|~/mnt}}:


  $ jmtpfs ~/mnt
  $ jmtpfs ~/mnt
Unmount device mounted on {{ic|~/mnt}}:
$ fusermount -u ~/mnt


Make this cohere to the rest of Linux (use regular mount/umount commands) by doing two steps
Make this cohere to the rest of Linux (use regular mount/umount commands) by doing two steps
Line 90: Line 66:
  $  ln -s /sbin/jmtpfs                        /sbin/mount.jmtpfs
  $  ln -s /sbin/jmtpfs                        /sbin/mount.jmtpfs


add this line to /etc/fstab;  
add this line to {{ic|/etc/fstab}};  


   #jmtpfs <mount path>        fuse nodev,allow_other,<other options>                            0    0
   #jmtpfs <mount path>        fuse nodev,allow_other,<other options>                            0    0
Line 104: Line 80:
   jmtpfs on /home/sam/run/motog type fuse.jmtpfs (rw,nosuid,nodev,noexec,noatime,user_id=1000,group_id=1000,allow_other,user=sam)
   jmtpfs on /home/sam/run/motog type fuse.jmtpfs (rw,nosuid,nodev,noexec,noatime,user_id=1000,group_id=1000,allow_other,user=sam)


=== go-mtpfs ===
=== SIMPLE-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.}}
{{App|SIMPLE-MTPFS|based on [[#libmtp|libmtp]] Simple Media Transfer Protocol FileSystem is a file system capable of operating on files on MTP devices attached via USB to local machine|https://github.com/phatina/simple-mtpfs/|{{AUR|simple-mtpfs}}}}


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>}}.
Run {{ic|simple-mtpfs -l}} to list detected devices.


Mount device on {{ic|~/mnt}}:
To mount the first device in the list to {{ic|~/mnt}}, run {{ic|simple-mtpfs --device 1 ~/mnt}}.


$ go-mtpfs ~/mnt
=== go-mtpfs ===


Unmount device mounted on {{ic|~/mnt}}:
{{App|go-mtpfs|FUSE filesystem with custom MTP implementation, written in Go|https://github.com/hanwen/go-mtpfs|{{AUR|go-mtpfs-git}}}}


$ fusermount -u ~/mnt
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|1=OWNER="''user''"}}.


=== simple-mtpfs ===
Mount device on {{ic|~/mnt}}:


List MTP devices:
$ go-mtpfs ~/mnt


$ simple-mtpfs --list-devices
{{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}}
* 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.)
* This package has not been maintained since 2020.
}}


Mount your device on {{ic|~/mnt}}:
== libmtp ==


$ simple-mtpfs ~/mnt
[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}}).


Unmount device mounted on {{ic|~/mnt}}:
[[Install]] the {{Pkg|libmtp}} package.


$ fusermount -u ~/mnt
Run {{ic|mtp-detect}} to detect your device.


=== Android File Transfer ===
If an error is returned, make sure your user is in the {{ic|adbusers}} [[user group]].


;FUSE interface
You can transfer files using the {{ic|mtp-connect}} command.


Mount your device on {{ic|~/my-device}}:
=== Frontends ===
$ 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.
{{App|gMTP|A graphical frontend for libmtp. It lets you connect to Android devices and manage files using a desktop agnostic GUI.|https://gmtp.sourceforge.io/|{{Pkg|gmtp}}}}


Unmount device mounted on {{ic|~/my-device}}:
== Media players ==


$ fusermount -u ~/my-device
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).  
 
;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.
 
=== 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:
Run:


Line 165: Line 135:
Also reload udev rules:
Also reload udev rules:
  # udevadm control --reload
  # 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 {{Pkg|gvfs-mtp}} for MTP or {{Pkg|gvfs-gphoto2}} for PTP support.
* For file managers that use KIO (KDE's Dolphin), MTP support is included in {{Pkg|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 {{ic|mtp://[usb:002,013]/}}.


=== gvfs-mtp ===
=== gvfs-mtp ===
Line 174: Line 153:
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.
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.
  Bus '''002''' Device '''018''': ID '''04b7''':'''88a9''' Compal Electronics, Inc.
  Bus '''002''' Device '''018''': ID '''04b7''':'''88a9''' Compal Electronics, Inc.
(...)


To see detected device with enabled MTP
To see detected device with enabled MTP


Use ''gvfs-mount'':
Use ''gio mount'':


{{hc|<NOWIKI>gvfs-mount -li | grep -e ^Volume -e activation_root</NOWIKI>|2=
{{hc|gio mount -li {{!}} grep -e ^Volume -e activation_root|2=
Volume(0): MT65xx Android Phone
Volume(0): MT65xx Android Phone
   activation_root=mtp://[usb:'''002''','''018''']/
   activation_root=mtp://[usb:'''002''','''018''']/
Line 187: Line 165:
Use ''lsusb'':
Use ''lsusb'':


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


To mount all available connected MTP devices use inline script
To mount all available connected MTP devices use inline script


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


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/''.
To mount or dismount from a command with gvfs-mtp use Bus and Device numbers, e.g. to mount {{ic|gio mount mtp://[usb:001,007]/}} and to unmount {{ic|gio 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 {{ic|/usr/share/gvfs/mounts/mtp.mount}}.
To disable automount of MTP devices 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}}.


{{Note|The file managers can have own options for automount. On start they checking for all available mountable devices.}}
{{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 the {{Pkg|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
If your device is not 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


{{bc|1=Device 0 (VID=''XXXX'' and PID=''XXXX'') is UNKNOWN.
{{bc|1=Device 0 (VID=''XXXX'' and PID=''XXXX'') is UNKNOWN.
Line 223: Line 198:
  # udevadm control --reload
  # udevadm control --reload


The file managers with support for [[gvfs]] will be able to show MTP devices and mount them if supported by {{Pkg|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]/}}.
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|gio 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. {{ic|cp}},{{ic|ls}} then look for [[gvfs]] own alternatives, {{ic|ls -1 /usr/bin/gvfs-*}}.}}
{{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-*}}.}}
Line 229: Line 204:
== Troubleshooting ==
== Troubleshooting ==


=== libmtp ===
=== libmtp (gvfs-mtp): filemanager (nautilus, pcmanfm, vifm and etc) hangs on accessing DCIM/Camera of Android device ===


==== Unable to enumerate USB device ====
Symptoms: everything works fine till moment of entering DCIM/Camera directory. In this case filemanager freezes and even in command line you cannot run even {{ic|ls}} on that directory.
{{Deletion|This should be an old kernel bug, and should have been fixed already. There is no bug report to confirm though.}}
{{Merge||Unrelated to MTP, perhaps suited for [[USB storage devices]]}}


If you see a message like this in system log ({{ic|journalctl}})
Possible and very probable reason is the bug of libmtp.


  usb usb4-port2: unable to enumerate USB device
It seems that it is caused by file with name like {{ic|20180915_180351(0).jpg}}. Samsung phones for example like to create files with such names.


You can try following temporary [https://bbs.archlinux.org/viewtopic.php?pid=1087323#p1087323 workaround]
There are several tickets ([https://sourceforge.net/p/libmtp/bugs/1830/ one], [https://sourceforge.net/p/libmtp/bugs/1808/ two] and etc) and questions ([https://askubuntu.com/questions/995383/nautilus-hangs-on-accessing-dcim-camera-on-android one], [https://askubuntu.com/questions/1030736/cant-open-photos-stored-on-android-system-from-ubuntu/1148034#1148034 two]) about it.


  # modprobe -vr uhci_hcd
So possible workaround is to use different mtp option from [[#FUSE filesystems]] like go-mtpfs for such directories or somehow change file naming policy of your phone camera (or switch to another camera app like [https://opencamera.sourceforge.io/ Open Camera] for example).
  # modprobe -va ohci_hcd
  # modprobe -va uhci_hcd


If it works you should create {{ic|/etc/modprobe.d/usb_hci_order.conf}} with following content
=== jmtpfs: Input/output error upon first access ===


  # create a dependency on ohci for uhci, which fixes problems
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:
  # with external usb devices not showing up
  #
  softdep uhci_hcd pre: ohci_hcd


=== jmtpfs ===
  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.


==== Input/output error upon first access ====
=== kio-mtp: cannot use "Open with File Manager" action ===


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:
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}}.


  cannot access <mount-point>: Input/output error
Change the line {{ic|1=Exec=kioclient exec mtp:udi=%i/}} to {{ic|1=Exec=dolphin "mtp:/"}}.


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 being called simultaneously by different services ===


=== kio-mtp ===
Parallel usage of mtpfs and kio-mtp, as well as conflicting services using kio-mtp -music players included- should be avoided, as mentioned in [https://bbs.archlinux.org/viewtopic.php?pid=1657736#p1657736 this forum].


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/apps/solid/actions/solid_mtp.desktop}}.
Amarok's plugin for MTP services, for example, might be preventing Dolphin (plasma) to access different phone model's files. Switching it off was a solution for at least one user.


Change the line
=== Android File Transfer: connect failed: no MTP device found ===


Exec=kioclient exec mtp:udi=%i/
After installing {{Pkg|android-file-transfer}}, while trying to mount any MTP device if you get the following error:


To
{{hc|$ aft-mtp-mount /path/to/folder|
connect failed: no MTP device found
}}


Exec=dolphin "mtp:/"
then install the package: {{Pkg|android-udev}}. This package contains per manufacturer/device [[udev rules]] for MTP devices, making it easier to use [[ADB]] or MTP.

Latest revision as of 13:21, 14 April 2024

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.

Note: MTP is messy and its implementation varies between devices. Try the below clients and 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 in the examples below.

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

Android File Transfer

Android File Transfer — MTP client with CLI, Qt UI, and FUSE wrapper which uses a custom MTP implementation

https://whoozle.github.io/android-file-transfer-linux/ || android-file-transfer

Mount your device on ~/mnt:

$ aft-mtp-mount ~/mnt

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.

If you want to interact with it via the command line interface, run the command:

$ aft-mtp-cli

Type help in order to list all the commands available, exit to quit.

If you want to interact with it via the graphical user interface, start the android-file-transfer 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.

MTPfs

MTPfs — based on libmtp, it is a FUSE filesystem that supports reading and writing from any MTP device

https://www.adebenham.com/mtpfs/ || mtpfs
Note: The following is likely to not work and you might have to resort to libgphoto2 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

jmtpfs — based on libmtp for accessing MTP (Media Transfer Protocol) devices

https://github.com/JasonFerrara/jmtpfs || jmtpfsAUR

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

SIMPLE-MTPFS — based on libmtp Simple Media Transfer Protocol FileSystem is a file system capable of operating on files on MTP devices attached via USB to local machine

https://github.com/phatina/simple-mtpfs/ || simple-mtpfsAUR

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

go-mtpfs — FUSE filesystem with custom MTP implementation, written in Go

https://github.com/hanwen/go-mtpfs || go-mtpfs-gitAUR

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
  • 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.)
  • This package has not been maintained since 2020.

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 adbusers user group.

You can transfer files using the mtp-connect command.

Frontends

gMTP — A graphical frontend for libmtp. It lets you connect to Android devices and manage files using a desktop agnostic GUI.

https://gmtp.sourceforge.io/ || gmtp

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

This article or section is a candidate for merging with udev.

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 gio mount:

gio 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

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

To mount or dismount from a command with gvfs-mtp use Bus and Device numbers, e.g. to mount gio mount mtp://[usb:001,007]/ and to unmount gio 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/.

To disable automount of MTP devices 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 is not 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: gio 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

libmtp (gvfs-mtp): filemanager (nautilus, pcmanfm, vifm and etc) hangs on accessing DCIM/Camera of Android device

Symptoms: everything works fine till moment of entering DCIM/Camera directory. In this case filemanager freezes and even in command line you cannot run even ls on that directory.

Possible and very probable reason is the bug of libmtp.

It seems that it is caused by file with name like 20180915_180351(0).jpg. Samsung phones for example like to create files with such names.

There are several tickets (one, two and etc) and questions (one, two) about it.

So possible workaround is to use different mtp option from #FUSE filesystems like go-mtpfs for such directories or somehow change file naming policy of your phone camera (or switch to another camera app like Open Camera for example).

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:/".

kio-mtp being called simultaneously by different services

Parallel usage of mtpfs and kio-mtp, as well as conflicting services using kio-mtp -music players included- should be avoided, as mentioned in this forum.

Amarok's plugin for MTP services, for example, might be preventing Dolphin (plasma) to access different phone model's files. Switching it off was a solution for at least one user.

Android File Transfer: connect failed: no MTP device found

After installing android-file-transfer, while trying to mount any MTP device if you get the following error:

$ aft-mtp-mount /path/to/folder
connect failed: no MTP device found

then install the package: android-udev. This package contains per manufacturer/device udev rules for MTP devices, making it easier to use ADB or MTP.