How to access files on MTP device from command line?

From an internet search, I found https://forums.opensuse.org/showthread.php/508339-How-can-I-manage-files-on-an-MTP-device-from-command-line (A search on the forum for the last year yielded no relevant results.)

It is my understanding from that, that the file system should already be mounted (automatically). However, the info provided there no longer appears to work.

lsusb 
...]
Bus 002 Device 004: ID 22b8:2e82 Motorola PCS XT1541 [Moto G 3rd Gen] 
...]

(Side note: Is the udev database incorrect since gvfs says it is a XT1028?)

ls -a /run/user/1000/gvfs/mtp:host=[usb:002,004]/          
ls: cannot access '/run/user/1000/gvfs/mtp:host=[usb:003,002]/': No such file or directory
mount |grep fuse 
**fuse**ctl on /sys/fs/**fuse**/connections type **fuse**ctl (rw,nosuid,nodev,noexec,relatime) 
gvfsd-**fuse** on /run/user/1000/gvfs type **fuse**.gvfsd-**fuse** (rw,nosuid,nodev,relatime,user_id=1000,group_id=100) 
portal on /run/user/1000/doc type **fuse**.portal (rw,nosuid,nodev,relatime,user_id=1000,group_id=100)

GIO says it’s mounted. At least I think that’s what the existence of this particular listing means.

gio mount -l | grep -B1 MTP 
Volume(0): XT1028 
  Type: GProxyVolume (GProxyVolumeMonitor**MTP**)

Do I need to install mtpfs, simple-mtpfs, and/or mtpfs-tools to get access to the files on the device via command line? Dolphin file manage (yes, I use KDE) has no problem with accessing the files. Why can’t I?

I caught this too late to edit the original post. The correct package name is “mtp-tools” not “mtpfs-tools”.

Yes, install the package “mtp-tools” from the main openSUSE repository.

Thank you for the response.

However, after installing mtp-tools, I still cannot access the the device via MTP from the command line:

user@linux-desktop:~> ls -a /run/user/1000/gvfs/mtp:host=[usb:002,004]/ 
ls: cannot access '/run/user/1000/gvfs/mtp:host=[usb:002,004]/': No such file or directory

It appears that these tools are to be used manually as an interface to a MTP device, not to provide transparent access via standard shell commands (eg. ls, cat, cp, etc.). It is difficult to determine exactly what their purpose and usage is as there is no man page for any of them nor do they provide any usage “–help”.

Even though the system automatically mounts the device on a FUSE using gvfs, I guess it’s not possible to access the device from the command line directly. Oh well.

Thanks again.

To begin with I have no idea of what a MTP device is. But the fact that you talk about mounting and accessing files tells me that it is about mass storage in some form.

Now first of course it must be mounted. You never told us how it is mounted, nor even did you show that it is mounted.

mount -a

You only show with an “ls” command that some file does not exist. I can show you many files that do not exist. Please first show why you think that file should exist.

Also mark that you try to access something inside /run/user/1000/, which means to me that you are meddling with a logged in user (uid=1000) in the GUI. What has that user to do with this? And who is the person (user) that wants to access files in the file system on the device? Again, the system does not recognize an “I” or “me”, it only recognizes users defined by UID and having a user name.

I was using “MTP device” as shorthand for “a device that used the Media Transfer Protocol”. Media Transfer Protocol - Wikipedia
I thought that would be understood since this convention was also used in the forum thread I linked in my original post:
https://forums.opensuse.org/showthread.php/508339-How-can-I-manage-files-on-an-MTP-device-from-command-line

Well I didn’t show that the actual device itself is mounted because I thought it was mounted automatically on a File System in User Space (FUSE) per the forum thread to which I linked. I did, however, show that the FUSE was mounted at ‘/run/user/1000/gvfs’:

mount |grep fuse 
fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime) 
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=100) 
portal on /run/user/1000/doc type fuse.portal (rw,nosuid,nodev,relatime,user_id=1000,group_id=100)

I thought it should exist due to what I read in the forum thread to which I linked. More specifically this post:
https://forums.opensuse.org/showthread.php/508339-How-can-I-manage-files-on-an-MTP-device-from-command-line?p=2717754#post2717754

No, I am not meddling with a user in the GUI. I am using the command line to try to access a device over MTP which I thought I should be able to do per the forum thread to which I linked. And, I thought it would be a logical deduction that I am the user with userid=1000.

Perhaps I should have made my post in the Hardware sub-forum?

I did not say that the term MTP is not understood in general, I only informed you about the fact that I am not fluent with it. So that you can have an idea about the value of what I say. It just to explain that I try to unravel and understand what you are doing. Looking in a place that you say should exist, but it doesn’t.

I also see that you tried to post what is mounted, but I doubt about the new lines there. I can not really see what belongs to what.
But I see two mount points mentioned there

/run/user/1000/gvfs
run/user/1000/doc

Both are not the place where you try to look

/run/user/1000/gvfs/mtp:host=[usb:002,004]/

What about looking in the mount point mentioned there first?

ls -la /run/user/1000/gvfs

I did try looking in /run/user/1000/gvfs first and found nothing but the ‘dot’ files. Therefore, I thought that was the wrong way to do it and so tried using the /run/user/1000/gvfs/mtp:host=[usb:002,004]/ syntax as shown by malcolmlewis in this post which I linked earlier:
https://forums.opensuse.org/showthread.php/508339-How-can-I-manage-files-on-an-MTP-device-from-command-line?p=2717754#post2717754

Anyway, I rebooted my system to start clean and then tried to determine when, exactly, the gvfsd-fuse mount is triggered. Nothing that I tried, including attaching and reattaching the device and launching Dolphin to view files on the device, triggered the FUSE mount and the creation of the /run/user/1000/gvfs directory. Given the content of that other forum thread, I thought it would.

I discovered, quite by accident, that Firefox is triggering it, not the attachment of a MTP device.

So, I installed simple-mtpfs and have tried, unsuccessfully, to figure out how to get it to mount the device. Oh well, I’m not going to spend any more time on this. The KDE Panel Device Notifier widget allows me to launch Dolphin to browse files on the device. That will have to suffice.

Thank you for the time you spent trying to help.

Can you please, take a look at where Dolphin has accessed the device.

  • Click on the grey area to the right of the Dolphin Location Bar to switch to an Edit Mode which displays the full path to the directory.
  • Clicking on the “>” to the left of the Location Bar will display a directory tree which ain’t much use for pasting to the MTP Tools …

Please check if, the MTP Tools can access the directory path Dolphin is using.

I think I should have been more clear when I said:

However, after installing mtp-tools, I still cannot access the the device via MTP from the command line:

What I meant was by using standard shell commands like ls as was shown in the other thread I linked, eg.:
ls /run/user/1000/gvfs/mtp:host=[usb:003,002]/

The location Dolphin uses to access the device is:
mtp:/XT1028/
If I click on the device, under Devices in Dolphin’s Places tab, the title of the Dolphin window is:
mtp:udi=/org/kde/solid/udev/sys/devices/pci0000:00/0000:00:13.2/usb2/2-4

I don’t know how to do that. It seems that mtp-tools comes with no documentation nor any ‘–help’ option.

With no device connected:

user@linux-desktop:~> man mtp-tools
No manual entry for mtp-tools

user@linux-desktop:~> man mtp-detect
No manual entry for mtp-detect

user@linux-desktop:~> man mtp-connect
No manual entry for mtp-connect

user@linux-desktop:~> mtp-detect --help
mtp-detect: invalid option -- '-'
mtp-detect: invalid option -- 'h'
mtp-detect: invalid option -- 'e'
mtp-detect: invalid option -- 'l'
mtp-detect: invalid option -- 'p'
libmtp version: 1.1.16

Listing raw device(s)
   No raw devices found.

user@linux-desktop:~> mtp-connect --help
libmtp version: 1.1.16

No devices.

After attaching the device:
Relevant line from lsusb:

Bus 002 Device 002: ID 22b8:2e82 Motorola PCS XT1541 [Moto G 3rd Gen]
mtp-detect
libmtp version: 1.1.16

Listing raw device(s)
Device 0 (VID=22b8 and PID=2e82) is a Motorola Moto G (ID2).
   Found 1 device(s):
   Motorola: Moto G (ID2) (22b8:2e82) @ bus 2, dev 2
Attempting to connect device(s)
error returned by libusb_claim_interface() = -6LIBMTP PANIC: Unable to initialize device
Unable to open raw device 0
OK.
user@linux-desktop:~> mtp-connect
libmtp version: 1.1.16

Device 0 (VID=22b8 and PID=2e82) is a Motorola Moto G (ID2).
error returned by libusb_claim_interface() = -6LIBMTP PANIC: Unable to initialize device
No devices.

Is that the information you wanted?

You need to take a look at what the “mtp-tools” package contains – use “rpm --query --list mtp-tools” to peek into the package’s contents.

  • You’re correct – there ain’t no documentation – there ain’t no man pages – there ain’t no package containing documentation.

There’s only the executable files in the package, which presumably have “-h” and “–help” command line options.

  • mtp-albumart
  • mtp-albums
  • mtp-connect
  • mtp-delfile
  • etc, etc, etc …

**@tleedavidson:
**
There’s this ArchLinux page dealing with Media Transfer Protocol (MTP): <https://wiki.archlinux.org/title/Media_Transfer_Protocol>.

  • But, on reading that information, I have to ask “Why bother?” …

There’s a KDE application which elegantly deals with this task without any effort –

[INDENT=3] Receive your phone notifications on your desktop computer and reply to messages
Control music playing on your desktop from your phone
Use your phone as a remote control for your desktop
Run predefined commands on your PC from connected devices. See the list of example commands for more details.
Check your phone’s battery level from the desktop
Ring your phone to help find it
Share files and links between devices
Browse your phone from your desktop
Control the desktop’s volume using your phone
Send SMS from your desktop[/INDENT]

Once you have the mobile telephone connected via KDE Connect, you can open the telephone in a Dolphin window and from there, open a Konsole session at that address – you’re connected to your telephone by means of SFTP – the directory looks like this:


 > pwd
/run/user/1000/98298fce769135ce
 > 
 > ls
DCIM  Documents  Media  Pictures  Sicherungen
 > 

Yes, that is what I did and how I knew the mtp-detect and mtp-connect utilities existed.

Nope, no “–help” available; at least not for those two I tried. From my previous post:

user@linux-desktop:~> mtp-detect --help
mtp-detect: invalid option – ‘-’
mtp-detect: invalid option – ‘h’
mtp-detect: invalid option – ‘e’
mtp-detect: invalid option – ‘l’
mtp-detect: invalid option – ‘p’
libmtp version: 1.1.16

Listing raw device(s)
No raw devices found.

user@linux-desktop:~> mtp-connect --help
libmtp version: 1.1.16

No devices.

And, just now:

user@linux-desktop:~> mtp-detect -h 
mtp-detect: invalid option -- 'h' 
libmtp version: 1.1.16 

Listing raw device(s) 
   No raw devices found.

There is some very good information on that page including a githup repo that has grabbed my interest. Thank you very much for that.

Well, I probably wouldn’t have, but I was trying to help a developer on a programming mailing list with his media backup application. I didn’t mention that originally because I thought it wasn’t relevant.

I do use KDE Connect with this phone. But, I did not know that I could browse files with a file manager and use standard shell commands to access the device over KDE Connect. I thought I had to use the KDE Connect menu. Wow, very cool!

Thanks again, dcurtisfra.

So, now a question –

  • Is there any need to use a tool without documentation that supposedly supports Microsoft’s Media Transfer Protocol?

Or,

  • Is the KDE Connect tool (with documentation) which uses SFTP to access the remote device (which is running a Linux anyway … ), sufficient to support the tasks you wish to perform?

It is sufficient for my personal needs. But, it is insufficient for the needs of the software developer I was trying to help. I guess he’ll just have to find an alternative solution.

The above error can manifest when another application (eg Dolphin) is already accessing the device in question.