Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have an Android phone that connects with my computer via MTP. This works fine; I can see and transfer files with Nautilus. However, I often want to use the terminal to move large numbers of files, and I cannot seem to find the device anywhere in the filesystem tree. Nautilus reports the location as mtp://[usb:003,007]/, but it's not under /media or /mnt.

Does anyone know where it is?

share|improve this question
add comment

3 Answers 3

up vote 8 down vote accepted

Asker's edit: This seems to require a newer version of libmtp and/or gvfs than is available per default in 13.04. Run sudo add-apt-repository ppa:langdalepl/gvfs-mtp and update before doing anything else.


Edit: PPA not needed anymore in saucy/13.10, filenames are listed in terminal as they are in Nautilus.


As you have already found out, the mountpoints are in /run/user/$USER/gvfs/ and are named after the protocol, connection type and address they use. Which makes things more difficult, because the connection address may change every time you replug the device, even if it is the same port. If you have the same device twice it gets even worse.

You can use lsusb to display all connected USB devices from terminal:

$ lsusb | grep Google                       # Note: This is a Nexus 4
Bus 002 Device 025: ID 18d1:4ee2 Google Inc.

As you have noticed Nautilus also gives this information via tool tip. You will find the encoded form of e.g. mtp://[usb:002,025] in /run/user/$USER/gvfs as mtp:host=%5Busb%3A002%2C025%5D

A shell script would look like this:

#/bin/bash

# Find the path to MTP/PTP connected device by USB ID
find_path_by_usbid () {
        lsusboutput="$(lsusb | grep $1 | head -n1)"
        usbbus="${lsusboutput% Device*}"
        usbbus="${usbbus#Bus }"
        usbdevice="${lsusboutput%%:*}"
        usbdevice="${usbdevice#*Device }"

        # Media Transfer Protocol
        if [ -d "$XDG_RUNTIME_DIR" ]; then
            runtimedir="$XDG_RUNTIME_DIR"
        else
            runtimedir="/run/user/$USER"
        fi
        MtpPath="$runtimedir/gvfs/mtp:host=%5Busb%3A${usbbus}%2C${usbdevice}%5D"
        # Picture Transfer Protocol
        PtpPath="$runtimedir/gvfs/gphoto2:host=%5Busb%3A${usbbus}%2C${usbdevice}%5D"

        if [ -d "$MtpPath" ]; then
                echo "$MtpPath"
        elif [ -d "$PtpPath" ]; then
                echo "$PtpPath"
        else
                echo "Error: File or directory was not found." 
        fi
}

# USB ID for Nexus 4
Id="18d1:4ee2"
Path="$(find_path_by_usbid $Id)"

# Backup pictures if device is connected
if [ "$Path" == "Error: File or directory was not found." ]; then
        echo "$Path"
        exit
else
        rsync -av --progress $Path/DCIM/Camera/ ~/Pictures/Backup_Nexus4/
fi
share|improve this answer
    
Thank you for your answer. Unfortunately, it doesn't work because the actual folder names (e.g. /DCIM/Camera/) are only visible in Nautilus, not the terminal. Thus, $Path/DCIM/Camera is not accessible with rsync. –  bessman Sep 8 '13 at 14:16
    
The path is just an example and is different for Android phones. The phone must also be unlocked via lock screen to allow access to the data. –  LiveWireBT Sep 8 '13 at 15:37
    
The path /DCIM/Camera/ exists on my phone, but in the terminal it is called /2404/2407/. That's the problem. If I cd into /2404/2407/ and run nautilus ., then /DCIM/Camera/ is opened. The phone is unlocked, otherwise I wouldn't be able to access it via Nautilus, right? –  bessman Sep 8 '13 at 17:37
    
That's odd, there should be no difference between Terminal and Nautilus. I don't know details of how MTP works on a deeper level and where your issue is rooted. You could try switching to PTP protocol and see if you get proper file names in this mode. My desktop runs on 12.10 with GVFS-MTP PPA and my phone runs CM 10.2 nightlies. –  LiveWireBT Sep 9 '13 at 14:22
1  
I forgot this is StackExchange and I can just do it myself. Thanks again! –  bessman Sep 10 '13 at 15:03
show 2 more comments

Type mount. That will list every active filesystem.

share|improve this answer
    
No, the device does not show up in the output. –  LiveWireBT Sep 6 '13 at 22:54
    
Hmm. That sort of worked. I found it under /run/user/myusername/gvfs/. However, all the foldernames are just numbers instead of the actual names that I see in Nautilus. As such, it doesn't really solve my problem because I still can't easily use the terminal to move files to the device. –  bessman Sep 7 '13 at 7:21
    
When Nautilus has the MTP device open, use the commands lsof -c nautilus | less to list all file files Nautilus has open. –  waltinator Feb 3 at 19:13
add comment

This is not a direct answer to the problem, but a solution none the less..

After experiencing inconsistency's with USB connectivity, I bypassed the .gvfs and USB system all together.

I installed a simple ftp server on the android and whoala! Connect to server (either ftp with login or without, depending on how you choose) from Nautilus/nemo/thunar and away ya go.

Syncronisation of folders is handled through OwnCloud and/or BitTorrentSync

And the FTP over wireless is way quicker than the USB connection was.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.