- Media Transfer Protocol
- Contents
- Connecting
- FUSE filesystems
- Android File Transfer
- MTPfs
- jmtpfs
- SIMPLE-MTPFS
- go-mtpfs
- libmtp
- Frontends
- Media players
- File manager integration
- gvfs-mtp
- Troubleshooting
- libmtp (gvfs-mtp): filemanager (nautilus, pcmanfm, vifm and etc) hangs on accessing DCIM/Camera of Android device
- jmtpfs: Input/output error upon first access
- kio-mtp: cannot use «Open with File Manager» action
- kio-mtp being called simultaneously by different services
- Android File Transfer: connect failed: no MTP device found
- How to mount Android (MTP)-Storage on Linux (openSuSE 12.1)
- Add a comment
- Comments (newest first)
Media Transfer Protocol
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).
Contents
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.
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
Mount your device on
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:
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
First edit your /etc/fuse.conf and uncomment the following line:
Mount your device on
jmtpfs
jmtpfs — based on libmtp for accessing MTP (Media Transfer Protocol) devices
Mount device on
Make this cohere to the rest of Linux (use regular mount/umount commands) by doing two steps
add this line to /etc/fstab ;
Now mount the device and see if the options «took»
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
Run simple-mtpfs -l to list detected devices.
To mount the first device in the list to
/mnt , run simple-mtpfs —device 1
go-mtpfs
go-mtpfs — FUSE filesystem with custom MTP implementation, written in Go
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=» » .
Mount device on
libmtp
libmtp is a library MTP implementation, which also comes with some example command-line tools (which you can list using pacman -Ql libmtp ).
Run mtp-detect to detect your device.
If an error is returned, make sure your user is in the uucp 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.
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:
Search for your device. It should be something like that:
And entry to /etc/udev/rules.d/51-android.rules will be this:
Also reload udev rules:
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.
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.
To see detected device with enabled MTP
To mount all available connected MTP devices use inline script
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/.
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 .
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
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
Reload the udev rules.
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]/ .
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:
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:
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.
Источник
How to mount Android (MTP)-Storage on Linux (openSuSE 12.1)
Published on July 27th 2012 — Listed in Android Linux
While connecting my Android phone (Samsung Galaxy S2, GT-I9000) to my Linux machine, running openSuSE 12.1, I got a bit disappointed, that the Android Storage is not detected automatically.
Android devices use MTP (Media Transfer Protocol) as the way to present the phone to a computer. The first devices which started that were some MP3 players (not iPods though!) and it is slowly becoming the new standard and replacing the «USB Mass Storage» mode. So much to some educational theory. Let’s get to practice.
Back in the year 2010, Mr. Chris Debenham was probably frustrated as I am and decided to program mtpfs, a way to mount such MTP devices using libmtp.
The following steps explain how mtpfs can be installed on Linux (here openSUSE 12.1) and how you mount (and unmount) the MTP storage.
1. Get the source code from Chris’ website:
2. Install dependencies for mtpfs.
Most of them are easy to install by using zypper:
# zypper install gcc
# zypper install fuse-devel
# zypper in libmtp-devel
# zypper in glib2-devel
# zypper in libid3tag-devel libid3tag
Another dependency is mad (libmad) but in openSUSE 12.1 this package is marked as unstable, therefore cannot be installed (by default) with zypper. As a workaround, one can download the rpm directly from the opensuse.com website. Don’t forget to get libmad0 and libmad0-devel RPM’s:
# wget http://download.opensuse.org/repositories/home:/mad_soft/openSUSE_12.1/x86_64/libmad-devel-0.15.1b-12.1.x86_64.rpm
# wget http://download.opensuse.org/repositories/home:/mad_soft/openSUSE_12.1/x86_64/libmad0-0.15.1b-12.1.x86_64.rpm
# rpm -ivh libmad*
warning: libmad-devel-0.15.1b-12.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID a795155b: NOKEY
Preparing. ########################################### [100%]
1:libmad0 ########################################### [ 50%]
2:libmad-devel ########################################### [100%]
3. Compile and install mtpfs:
# ./configure —prefix=/usr -sysconfdir=/etc
configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking for a BSD-compatible install. /usr/bin/install -c
checking whether build environment is sane. yes
checking for a thread-safe mkdir -p. /bin/mkdir -p
checking for gawk. gawk
checking whether make sets $(MAKE). yes
checking for gcc. gcc
checking whether the C compiler works. yes
checking for C compiler default output file name. a.out
checking for suffix of executables.
checking whether we are cross compiling. no
checking for suffix of object files. o
checking whether we are using the GNU C compiler. yes
checking whether gcc accepts -g. yes
checking for gcc option to accept ISO C89. none needed
checking for style of include used by make. GNU
checking dependency style of gcc. gcc3
checking whether gcc and cc understand -c and -o together. yes
checking for pkg-config. /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0. yes
checking for FUSE. yes
checking for MTP. yes
checking for GLIB. yes
checking for MAD. yes
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
# make
gcc -DPACKAGE_NAME=\»MTPfs\» -DPACKAGE_TARNAME=\»mtpfs\» -DPACKAGE_VERSION=\»1.1\» -DPACKAGE_STRING=\»MTPfs\ 1.1\» -DPACKAGE_BUGREPORT=\»Chris\ Debenham\ \ \» -DPACKAGE_URL=\»\» -DPACKAGE=\»mtpfs\» -DVERSION=\»1.1\» -DDEBUG=0 -I. -DFUSE_USE_VERSION=22 -D_FILE_OFFSET_BITS=64 -I/usr/include/fuse -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libusb-1.0 -DUSEMAD -g -O2 -MT mtpfs-mtpfs.o -MD -MP -MF .deps/mtpfs-mtpfs.Tpo -c -o mtpfs-mtpfs.o `test -f ‘mtpfs.c’ || echo ‘./’`mtpfs.c
mv -f .deps/mtpfs-mtpfs.Tpo .deps/mtpfs-mtpfs.Po
gcc -DPACKAGE_NAME=\»MTPfs\» -DPACKAGE_TARNAME=\»mtpfs\» -DPACKAGE_VERSION=\»1.1\» -DPACKAGE_STRING=\»MTPfs\ 1.1\» -DPACKAGE_BUGREPORT=\»Chris\ Debenham\ \ \» -DPACKAGE_URL=\»\» -DPACKAGE=\»mtpfs\» -DVERSION=\»1.1\» -DDEBUG=0 -I. -DFUSE_USE_VERSION=22 -D_FILE_OFFSET_BITS=64 -I/usr/include/fuse -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libusb-1.0 -DUSEMAD -g -O2 -MT mtpfs-id3read.o -MD -MP -MF .deps/mtpfs-id3read.Tpo -c -o mtpfs-id3read.o `test -f ‘id3read.c’ || echo ‘./’`id3read.c
mv -f .deps/mtpfs-id3read.Tpo .deps/mtpfs-id3read.Po
gcc -g -O2 -o mtpfs mtpfs-mtpfs.o mtpfs-id3read.o -pthread -lfuse -lrt -ldl -pthread -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -L/lib64 -lmtp -lusb-1.0 -lmad -lm -lid3tag
# make install
make[1]: Entering directory `/root/src/mtpfs-1.1′
test -z «/usr/bin» || /bin/mkdir -p «/usr/bin»
/usr/bin/install -c mtpfs ‘/usr/bin’
make[1]: Nothing to be done for `install-data-am’.
make[1]: Leaving directory `/root/src/mtpfs-1.1′
4. Connect your Android phone with USB cable. Make sure you disable the ‘USB Debug Mode’ (also called Android Debugging).
5. Mount the Android storage using mptfs. Note there is no device you need to tell the mtpfs command.
# mkdir /mnt/android
# mtpfs /mnt/android/
Listing raw device(s)
Device 0 (VID=04e8 and PID=6860) is a Samsung GT-P7310/P7510/N7000/I9100/Galaxy Tab 7.7/10.1/S2/Nexus/Note.
Found 1 device(s):
Samsung: GT-P7310/P7510/N7000/I9100/Galaxy Tab 7.7/10.1/S2/Nexus/Note (04e8:6860) @ bus 2, dev 5
Attempting to connect device
ignoring usb_claim_interface = -99Android device detected, assigning default bug flags
Reading in zero packet after header
Reading in zero packet after header
Reading in zero packet after header
Listing File Information on Device with name: (NULL
With df you can check the new mount point:
# df -h | grep mtp
mtpfs 12G 6.5G 5.1G 56% /mnt/android
6. Access the MTP storage. You can read files, copy files to the storage etc.
# ls /mnt/android/
Internal Storage Playlists
# cp /home/ckuenzler/Downloads/cm-9-20120726-NIGHTLY-galaxys2.zip /mnt/android/Internal\ Storage/
7. Unmount:
# fusermount -u /mnt/android
Update August 20th 2012:
After some tests I figured out that this MTP mount with mtpfs works only once after a reboot. Any additional mounts after an unmount or unplug of the Android device will fail. See comments for more details and error messages.
Update January 9th 2013:
I’m meanwhile on openSuSE 12.2 and this still doesn’t work properly. I gave jmtpfs a shot, which works fine the first mount, too. But again, after a umount and another mount, the following errors appear:
# jmtpfs /mnt/android/
Device 0 (VID=04e8 and PID=6860) is a Samsung GT-P7310/P7510/N7000/I9100/Galaxy Tab 7.7/10.1/S2/Nexus/Note.
ignoring usb_claim_interface = -99PTP_ERROR_IO: failed to open session, trying again after resetting USB interface
LIBMTP libusb: Attempt to reset device
ignoring usb_claim_interface = -99LIBMTP PANIC: failed to open session on second attempt
terminate called after throwing an instance of ‘MtpErrorCantOpenDevice’
what(): Can’t open device
Aborted
Add a comment
Comments (newest first)
dominobet from wrote on Oct 13th, 2014:
yh from SG wrote on Jan 30th, 2013:
Thanks for taking time to share this. At least now I can use mtpfs to mount the phone and copy content in/out.
Alexander from Schweiz wrote on Nov 5th, 2012:
I use Ubuntu and never got MTP to work flawlessly enough to be useful for me.
For that reason, I «switched» to using «adb» for all my file transfer needs. On the command line. In the year 2012.
We’re making quite some progress in usability, aren’t we. :/
Sandra from Germany wrote on Sep 1st, 2012:
Using Linux Mint 13, I am able to mount and umount my android device several times without rebooting. Also, I installed mtpfs via the repositories and did not compile it myself.
libusb is version 1.0.9
rc3-2ubuntu1 and libfuse is 2.8.6-2ubuntu2.
Claudio from Switzerland wrote on Aug 20th, 2012:
Hello Florian,
It is indeed the case: The mtpfs mount works only once after a reboot. After a fusermount -u (unmount) and another try to mount with mtpfs, the following error messages appear:
Attempting to connect device
ignoring usb_claim_interface = -99PTP_ERROR_IO: failed to open session, trying again after resetting USB interface
LIBMTP libusb: Attempt to reset device
ignoring usb_claim_interface = -99LIBMTP PANIC: failed to open session on second attempt
Unable to open raw device 0
It only works again after a reboot of the machine.
I completely agree: This is crap and _almost_ useless.
Claudio from Wil, Switzerland wrote on Aug 18th, 2012:
I am having issues to mount the Android storage now too. I’ve tried to mount the SGS2 several times on Friday, without success. Something crossed my mind: Once mounted with mtpfs, it won’t work anymore until a reboot. Will try that on Monday and will let you know.
Florian from Germany wrote on Aug 18th, 2012:
Sorry for the late Answer, i didn’t have time before.
Yes, I am using openSuSE 12.1, too.
My Versions of libfuse and libusb are the same as yours. Turning on or off USB Debugging Mode don’t make any difference, it doesn’t work at all. I can’t believe that I have to use Windows to access an Android Phone (Linux Kernel. )
That is such a crap!
A few minutes ago, I also tried to login as root. Nevertheless it didn’t work.
Claudio from Switzerland wrote on Aug 15th, 2012:
Important information: You must be root to mount the Android device. Otherwise an error like the following will appear:
libusb couldn’t open USB device /dev/bus/usb/002/003: Permission denied.
You can also run sudo mtpfs /mnt/android to gain sufficient permissions to access the USB device.
Claudio from Switzerland wrote on Aug 8th, 2012:
Are you also using OpenSuSE 12.1?
What’s your libusb and libfuse version?
Mine are:
— libfuse2-2.8.5-16.1.2.x86_64
— fuse-2.8.5-16.1.2.x86_64
— usbutils-004-2.1.2.x86_64
— libusb-1_0-0-1.0.8-9.1.2.x86_64
Also try with USB debugging enabled and once disabled. Always re-connect your USB cable after changing something.
In my case I also had to do a reboot when I upgraded my kernel and this had probably an impact on loaded kernel modueles.
Florian from Germany wrote on Aug 8th, 2012:
When I tried to mount my Samsung Galaxy S3 in this way, I got the following message:
> mtpfs /home/Florian/Arbeitsfläche/test/
Listing raw device(s)
libusb couldn\\\’t open USB device /dev/bus/usb/008/002: Permission denied.
libusb requires write access to USB device nodes.
libusb couldn\\\’t open USB device /dev/bus/usb/002/002: Permission denied.
libusb requires write access to USB device nodes.
libusb couldn\\\’t open USB device /dev/bus/usb/008/003: Permission denied.
libusb requires write access to USB device nodes.
Device 0 (VID=04e8 and PID=6860) is a Samsung GT-P7310/P7510/N7000/I9100/Galaxy Tab 7.7/10.1/S2/Nexus/Note.
Found 1 device(s):
Samsung: GT-P7310/P7510/N7000/I9100/Galaxy Tab 7.7/10.1/S2/Nexus/Note (04e8:6860) @ bus 1, dev 8
Attempting to connect device
PTP_ERROR_IO: failed to open session, trying again after resetting USB interface
LIBMTP libusb: Attempt to reset device
LIBMTP PANIC: failed to open session on second attempt
Unable to open raw device 0
Florian@linux-ls4i:
Источник