问题
I'm trying to access MTP device storage to automate file copy, backup, etc. If Windows Explorer is able to open and browse Android device Internal Storage and connected SD card, how can I access these storages with PowerShell?
I've found a lots of hints, such as "get device ID and use WMI"
What is the way the Windows Explorer uses to open and browse especialy Android's storages?
Is it possible to use some 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'm able to access and browse content of local MTP (android) device 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 information about stored pictures which is too slow even at local computer. Is it possible to avoid loading info about pictures to speed up loading and accessing remotely connected devices?
Thanks in advance for any information and hints!
回答1:
This is my first answer on Stack Overflow (Stack Exchange) please take it into the consideration.
I am dealing with the same issue - I want to be able to work with android internal storage in PowerShell as I am able in Explorer.
My only suggestion is that we could install FTP Server (my favourite is FTP Server)
and sort it this way. What I have found so far are these answers on superuser:
Open command prompt to access folders of a USB connected Android phone
13 votes & accepted
In order to assign a drive letter to a removable device, that device must support UMS (USB Mass Storage) protocol. Unfortunately most newer Android phones, especially those without a removable SD Card, do not support UMS. Instead, they support MTP (Media Transfer Protocol) and PTP (Picture Transfer Protocol) protocols. In such devices it's not possible to map storage as a drive in Windows.
See more details on this Superuser.com question: How do I access MTP devices on the command line in Windows?
24 votes & accepted
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.
edited May 12 '12 at 6:33 Peter Mortensen 8,075
answered Jan 10 '12 at 20:08 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, 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 '14 at 19:57
With that said, on some selected Samsung and Sony Android devices it's possible to enable the UMS mode for external storage only (SD Card). See this app SG USB Mass Storage Enabler.
Also, if your goal to simply copy files to and from an Android device via command prompt, ADB will allow you to do so. This utility is part of Android SDK tools. You will need USB drivers for your android phone to be installed, USB Debugging activated in Developer Settings on the phone, and authorize the PC to debug the phone (via a prompt on the device.) After that is done, you will be able to use adb push
and adb pull
commands to copy files & directories, and various Linux shell commands via adb shell <command>
(e.g.adb shell ls /sdcard/
) to navigate the directory structure on the phone.
edited Mar 20 '17 at 10:18
Community♦
1
answered Nov 21 '13 at 16:14
Chahk
18.5k
App mentioned in above answer looks to me very limiting because its age.
来源:https://stackoverflow.com/questions/44094188/access-mtp-storage-with-system-io-from-powershell