97

Most MTP (Media Transfer Protocol) devices show up in Windows File Explorer under their device name or a GUID, but they don't have a drive letter assigned.

How can I access the files on such devices from the command line? Using either cmd.exe or PowerShell.

4
  • 2
    The fact that the Linux MTP compatible implementations such as gphoto2 have a way to script uploading suggests that this should be possible on Windows somehow, assuming that Windows Media Player doesn't somehow block any other software from accessing the USB MTP interface... I too would like to know if this is possible.
    – Mokubai
    Dec 20, 2011 at 22:00
  • 2
    I gave up trying to find a solution for this with my Android MTP device and ended up installing a WebDAV server on my device. This could be mounted as a network drive, albeit slowly.
    – Mark Booth
    Oct 14, 2012 at 13:25
  • @MarkBooth I tried the WebDAV server but it seems most of the files I transfer are corrupt (over 90%)...
    – Michael
    Dec 24, 2016 at 18:20
  • Other solution for Android going the other way round, tweaking the connected device: 1, 2, 3.
    – Frédéric
    Jul 5, 2017 at 11:08

5 Answers 5

37

Unfortunately, APIs exposed by MTP are very different from a normal filesystem APIs. Therefore exposing MTP device as a read/write filesystem is not possible. The main reason:

Wikipedia says:

Neither the MTP nor the PTP standards allow for direct modification of objects. Instead, modified objects must be reuploaded in their entirety, which can take a long time for large objects. With PTP/MTP, the file size must be known at the opening stage.

Your common file copy program just opens a source and a target file, and copies data in chunks from the source file to the target. This won't work with MTP, since you need to use MTP special functions, and generic filesystem primitives (read, seek, write) are not available.

There are also other limitations. For example, the number of files that can be read or written simultaneously on an MTP device is severely limited. The device simply does not behave like a filesystem.

I suppose read-only filesystem driver for an MTP device might be possible, but because of the problems outlined above, it will be of very little use, so nobody bothered to create it.

2
  • 5
    The read-only filesystem driver seems to exist now: ptpdrive.com
    – Arne
    Sep 12, 2013 at 12:25
  • 11
    Actually, it's not "not possible". When you consider that I've got gphotofs and mtpfs as FUSE filesystems on Linux that're COMPLETELY Read/Write- its' quite possible to accomplish this as a "drive letter" under Windows...they've just not made it available or easy.
    – Svartalf
    May 9, 2014 at 19:57
12

There is a proprietary (but still nice) program: MTP Drive (https://www.mtpdrive.com/) which allows you to "mount" MTP devices as drives in Windows. With some reasonable limitations it does the great job!

3
  • 1
    1. Can that synthetic MTP drive be feed to a common drive data recovery tools like EASEUS/Recuva/R-Studio and data be recovered effeciently? 2. Can I use robocopy/other fast data transfer tools to transfer data from that drive to windows native drives(C/D etc.) efficiently?
    – Learner
    Aug 27, 2018 at 13:44
  • @SIslam, forget about efficiency in this case. Due to the first answer to the question, the nature of the API is too different.
    – barbalion
    May 14, 2020 at 17:38
  • 2
    Thank you, it worked for me! In python: os.path.exists("Z:\DCIM") == True where Z is the "drive" letter I assigned to my phone memory and DCIM where the pictures are.
    – Guimoute
    Mar 12, 2022 at 18:38
3

I've had success mounting a Garmin Descent Mk2i (to use with SubSurface Dive Log) using MTPMount (an open source project) Release 9.18.0 on Windows 10.

This has a dependency on installing Dokan (Dokany 1.5.1.1000) which exposes a FUSE filesystem to Windows apps.

NOTE 1: At the current time, the latest release (19.8.0, linked above) of MTPMount has not been updated to work with the latest v2.x Dokan, you need to use the 1.5.1.1000 Dokany Release

NOTE 2: MTPMount is a command line app and does not make it obvious what you have to type.
After a few minutes of failed attempts I found the following worked for me.

.\mtpmount-x64.exe mount "Descent Mk2i" "Primary"
6
  • Best answer. Windows Explorer doesn't work with thousands of files in one folder. With MTPMount I can access the files via command line now. But still for example "dir" in Powershell gets Timeout. robocopy is working great.
    – Michael
    Dec 1, 2022 at 21:10
  • Has anyone been able to get mtpmount to work with an iPhone or iPad? I can see the iPad with <mtpmount list available> but <mtpmount mount "#0"> or <mtpmount mount "Apple iPad" "Internal Storage"> both give the error: "Did not find any storage media named Internal Storage on Apple iPad. This might be due to wrong spelling or your device not being unlocked."
    – cynod
    Oct 4, 2023 at 5:45
  • I also tried mtpdrive and it sort of works but it's getting errors a lot and to copy >30 files, it is $50. For anyone just wanting to extract their photos from the clutches of Apple without succumbing to a @#$(*@ iCloud subscription, I've ended up doing this: FE File Explorer Pro doing a "backup" of the "Recents" album in the Photo Library to an "iPadBackup" SMB share on the unraid server. While it's going, it keeps hitting errors. I then open Windows Explorer, search for the filename, delete it, then hit the "backup" button again. OMG I hate apple
    – cynod
    Oct 4, 2023 at 19:51
  • With my Poco F5 Pro, this is not working, see github.com/hst125fan/mtpmount/issues/10. Please vote and/or comment, if you experience the same problem. The issue was ignored for more than a year now.
    – kriegaex
    Nov 7, 2023 at 2:58
  • Version 19.8.0 HAS A SERIOUS BUG WHICH COULD CAUSE DATA LOSS. Attempts to read a file up to its reported size may under some conditions succeed and yet return zeros as the data. Someone else reported as issue #5. I don't know if calls to DeleteFile can still succeed, but if so, catastrophic data loss could easily result if the application accessing the mount is trying to move files to other storage. Data could be lost even if the application tries to verify the copied data prior to deletion. Unfortunately this project seems to have been abandoned, so a fix is unlikely. Nov 9, 2023 at 1:39
1

You may be able to cobble something together with the MTP porting kit's MTPMon.

Alternatively, PowerShell can create COM objects and call their methods, so you may be able to use the APIs that Windows Explorer is using (for example, GetDeviceInfo() and GetObjectInfo()).

1
0

If it's true that Android phones use MTP to connect to pc's when in "File transfer" mode, than PowerShell is a solution, I just answered this on StackOverflow: https://stackoverflow.com/a/75543733/3090890

Slightly edited copy of my answer on StackOverflow below.

I found this PowerShell script: https://github.com/nosalan/powershell-mtp-file-transfer/ Disclaimer: I'm not the author of the script, so credits belong to him! Just for this answer, I copied and pasted code snippets from the linked source to provide it with some explanation.

The trick to access the phone, which should be in "File transfer" mode when connected through USB, is in this part:

$phoneName = "Nokia 7.2"    
$o = New-Object -com Shell.Application
$rootComputerDirectory = $o.NameSpace(0x11)
$phoneDirectory = $rootComputerDirectory.Items() | Where-Object {$_.Name -eq $phoneName} | select -First 1

Then you are able to traverse to the directory you want:

$sourceFolder = $phoneDirectory
$phoneFolderName = "Internal shared storage\DCIM\Camera"
foreach($pathSegment in ($phoneFolderName -split "\\"))
{
    $sourceFolder = $sourceFolder.GetFolder.Items() | Where-Object {$_.Name -eq $pathSegment} | select -First 1
    if($sourceFolder -eq $null)
    {
      throw "Not found $phoneFolderName folder"
    }
}

And finally copy items from the reached sourceFolder to the destination:

function Get-FullPathOfMtpDir($mtpDir)
{
    $fullDirPath = ""
    $directory = $mtpDir.GetFolder
    while($directory -ne $null)
    {
        $fullDirPath =  -join($directory.Title, '\', $fullDirPath)
        $directory = $directory.ParentFolder;
    }
    return $fullDirPath
}
$targetFolder = "E:\Test"
$destDirShell = (new-object -com Shell.Application).NameSpace($targetFolder)
$fullSourceDirPath = Get-FullPathOfMtpDir $sourceFolder 
foreach ($item in $sourceFolder.GetFolder.Items())
{
    $itemName = ($item.Name)
    $fullFilePath = Join-Path -Path $targetFolder -ChildPath $itemName

    if(Test-Path $fullFilePath)
    {
        Write-Host "Element '$itemName' already exists"
    }
    else
    {
        $copiedCount++;
        Write-Host ("Copying #{0}: {1}{2}" -f $copiedCount, $fullSourceDirPath, $item.Name)
        $destDirShell.CopyHere($item)
    }
}
Write-Host "Copied '$copiedCount' elements from '$fullSourceDirPath'"

It's also possible to copy files back to the phone. Here I swap the target and source as example, and copy "E:\Test\atestfileonpc.txt" to the phone's "DCIM\Camera" folder:

$sourceDirShell = (new-object -com Shell.Application).NameSpace($targetFolder)
$targetDirShell = $sourceFolder
$item = $sourceDirShell.Items() | Where-Object {$_.Name -eq "atestfileonpc.txt"} | select -First 1
targetDirShell.GetFolder.CopyHere($item)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .