Accessing MTP Store with System.IO from PowerShell

I am trying to access MTP device storage to automate file copying, backup, etc. If Windows Explorer can open and view the Android Internal Storage device and the attached SD card, how can I access those storages using PowerShell?

I found many tips like "get device id and use WMI"

How does Windows Explorer use Android special storages to open and view?

Is it possible to use some kind of System.IO class like here?

$drives = [System.IO.DriveInfo]::GetDrives()
$r = $drives | Where-Object { $_.DriveType -eq 'Removable' -and $_.IsReady }
if ($r) {
    return @($r)[-1]
}

      

I can access and view the contents of my local MTP device (android) with this:

$WIAdialog = New-Object -ComObject "WIA.CommonDialog"
$Device = $WIAdialog.ShowSelectDevice()
$Device = $WIAdialog.ShowAcquireImage()
$Device = $WIAdialog.ShowAcquisitionWizard()
$Device = $WIAdialog.ShowDeviceProperties()
$Device = $WIAdialog.ShowItemProperties()
$Device = $WIAdialog.ShowPhotoPrintingWizard()
$Device = $WIAdialog.ShowSelectItems()
$Device = $WIAdialog.ShowTransfer()

      

But this code is loading saved images information which is too slow even on local machine. Is it possible to avoid downloading snapshot information to speed up downloads and access to remotely connected devices?

Thanks in advance for any information and hints!

+3


source to share


1 answer


This is my first answer on Stack Exchange, please keep that in mind.

I am dealing with the same problem - I want to be able to work with android internal storage in PowerShell as I can in Explorer. My only suggestion is to set up an FTP server (my favorite FTP server ) and sort it that way. What I have found so far is the superuser answers:
Open command prompt to access folders of USB connected Android phone
13 voices and accepted

To assign a drive letter to a removable device, the device must support the UMS (USB Mass Storage) protocol. Unfortunately, most newer Android phones, especially those without a removable SD card, do not support UMS. Instead, they support the MTP (Media Transfer Protocol) and PTP (Picture Transfer Protocol) protocols. In such devices, it is not possible to display storage as a disk in Windows.

More on this Superuser.com question : How do I access MTP devices from the command line on Windows?

24 votes and accepted

Unfortunately, the APIs provided by MTP are very different from those of the regular filesystem. Therefore, exposing an MTP device as a read / write file system is impossible. The main reason:

Wikipedia says:

Neither MTP nor the PTP standards allow you to directly modify objects. Instead, modified objects must be completely reloaded, which can take a long time for large objects. With PTP / MTP, the file size must be known initially.

Your general file copy program simply opens the source and target file and copies the data into chunks from the source file to the target. This will not work with MTP as you need to use special MTP functions and the common filesystem primitives (read, search, write) are not available.

There are other restrictions as well. For example, the number of files that can be read or written at the same time on an MTP device is highly limited. The device just doesn't behave like a file system.

I suppose that a read-only filesystem driver for an MTP device might be possible, but due to the issues described above, this will be very small, so no one bothered to create it.

edited May 12 12 at 6:33 am Peter Mortensen 8075

answered Jan 10, 2012 at 08:08 PM haimg 15.9k

The read-only filesystem driver seems to exist now: ptpdrive.com - Arne de Bruijn Sep 12 '13 at 12:25



ptpdrive.com

Actually, this is not "impossible". When you think I have gphotofs and mtpfs as FUSE filesystems on Linux that are FULLY Read / Write - it's quite possible to do it as a "drive letter" under Windows ... they just didn't make it accessible or easy. - Svartalf May 9 at 14:57

With that said, on some select Samsung and Sony Android devices it is possible to enable UMS mode for external storage (SD card) only. See this SG USB Mass Storage Enabler appendix .

Also, if you just want to copy files to and from your Android device via the command line, ADB will let you do that. This utility is part of the Android SDK tools. You will need USB drivers for your Android phone to be installed, USB debugging is activated in developer settings on the phone and will allow the PC to debug the phone (via a prompt on the device). You will then be able to use commands adb push

and adb pull

to copy files and directories and various Linux shell commands through adb shell <command>

(for example adb shell ls /sdcard/

) to navigate the directory structure on the phone.

edited Mar 20 '17 at 10:18
Community ♦
1
replied 11/21/2011 at 4:14 PM
Chah

18.5k

The app mentioned in the above answer looks very limited because of its age.

0


source







All Articles