从PowerShell使用System.IO访问MTP存储 [英] Access MTP storage with System.IO from PowerShell

查看:280
本文介绍了从PowerShell使用System.IO访问MTP存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问MTP设备存储以自动执行文件复制,备份等操作. 如果Windows资源管理器能够打开和浏览Android设备的内部存储和已连接的SD卡,那么如何使用PowerShell访问这些存储?

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?

我发现了很多提示,例如获取设备ID和使用WMI"

Windows资源管理器用来打开和浏览特别是Android的存储的方式是什么?

What is the way the Windows Explorer uses to open and browse especialy Android's storages?

我可以通过以下方式访问和浏览本地MTP(android)设备的内容:

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()

但是此代码正在加载有关已存储图片的信息,即使在本地计算机上,该信息也太慢.是否可以避免加载有关图片的信息以加快加载和访问远程连接的设备的速度?

在此先感谢您提供任何信息和提示!

Thanks in advance for any information and hints!

推荐答案

这是我对Stack Overflow(Stack Exchange)的第一个答案,请考虑在内.

我正在处理相同的问题-我希望能够像在资源管理器中一样在PowerShell中使用android内部存储. 我唯一的建议是我们可以安装FTP服务器(我最喜欢的是 FTP服务器) 并以这种方式对其进行排序.到目前为止,我发现的是超级用户的以下答案:
打开命令提示符以访问文件夹USB连接的Android手机
13票&接受

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

为了将驱动器号分配给可移动设备,该设备必须支持UMS(USB大容量存储)协议.不幸的是,大多数较新的Android手机,尤其是那些没有可移动SD卡的Android手机,均不支持UMS.相反,它们支持MTP(媒体传输协议)和PTP(图片传输协议)协议.在此类设备中,无法将存储映射为Windows中的驱动器.

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.

在此Superuser.com上查看更多详细信息

See more details on this Superuser.com question: How do I access MTP devices on the command line in Windows?

24票&接受

24 votes & accepted

不幸的是,MTP公开的API与普通文件系统API完全不同.因此,不可能将MTP设备公开为读/写文件系统.主要原因:

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:

MTP和PTP标准均不允许直接修改对象.取而代之的是,必须完整地重新上传已修改的对象,这对于大型对象可能会花费很长时间.对于PTP/MTP,必须在打开阶段就知道文件大小.

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.

您的通用文件复制程序仅打开源文件和目标文件,然后将数据块从源文件复制到目标文件.这不适用于MTP,因为您需要使用MTP特殊功能,并且通用文件系统原语(读取,查找,写入)不可用.

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.

还有其他限制.例如,在MTP设备上可以同时读取或写入的文件数受到严重限制.该设备的行为根本不像文件系统.

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.

我认为MTP设备的只读文件系统驱动程序是可能的,但是由于上述问题,它的用处很小,因此没有人愿意创建它.

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.

编辑时间:2012年5月12日6:33 彼得·莫滕森 8,075

edited May 12 '12 at 6:33 Peter Mortensen 8,075

回答了2012年1月10日20:08 海姆格 15.9k

answered Jan 10 '12 at 20:08 haimg 15.9k

该只读文件系统驱动程序似乎现在存在:ptpdrive.com – Arne de Bruijn 2013年9月12日,12:25

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

ptpdrive.com

实际上,这并非不可能".当您考虑将gphotofs和mtpfs作为完整的Linux上的FUSE文件系统进行读/写时-在Windows下很可能以驱动器号"的形式完成此操作……他们只是没有提供它还是容易. –斯瓦尔塔夫夫(Svartalf),2014年5月9日,19:57

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

话虽如此,在某些选定的Samsung和Sony Android设备上,可以为仅外部存储(SD卡)启用UMS模式. 请参见此应用SG USB海量存储启动器.

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.

此外,如果您的目标是通过命令提示符简单地在Android设备之间来回复制文件,则ADB将允许您这样做.该实用程序是Android SDK工具的一部分.您将需要安装Android手机的USB驱动程序,并在手机的开发人员设置"中激活USB调试,并授权PC调试手机(通过设备上的提示.)完成后,您将能够使用adb pushadb pull命令复制文件&目录,以及通过adb shell <command>(例如adb shell ls /sdcard/)的各种Linux Shell命令来导航手机上的目录结构.

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.

编辑时间:2017年3月20日10:18
社区♦
1
13年11月21日在16:14回答
查克

18.5k

edited Mar 20 '17 at 10:18
Community♦
1
answered Nov 21 '13 at 16:14
Chahk

18.5k

应用在我看来非常有限,因为它的年龄.

这篇关于从PowerShell使用System.IO访问MTP存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆