Python code to access devices using the Windows Portable Devices API (e.g. Media Transfer Protocol - MTP - devices)
For now, only directory listing and transfer to the device is implemented.
- Get comtypes.
- Next you need let comtypes build the interfaces. I needed to fiddle around the generated code, to get it working:
- comment-in the
comtypes.client.GetModule(...)
lines (or call both from Python console) - Then I had to define some parameters as in-out that were just out parameters. In
_1F001332_1A57_4934_BE31_AFFC99F4EE0A_0_1_0.py
(found it inC:\Python27\Lib\site-packages\comtypes\gen
):- In
IEnumPortableDeviceObjectIDs
, in functionNext
change the parameterpObjIDs
to['in', 'out']
- In
IPortableDeviceContent
, in functionCreateObjectWithPropertiesAndData
change the parameterppData
to['in', 'out']
- In
ISequentialStream
, in functionRemoteRead
change the parameterspv
andpcbRead
to['in', 'out']
- In
IPortableDeviceResources
, in functionGetStream
change the parameterppStream
to['in', 'out']
- In
- Remove all bad asserts from the generated files (
_1F001332_1A57_4934_BE31_AFFC99F4EE0A_0_1_0.py
and_2B00BA2F_E750_4BEB_9235_97142EDE1D3E_0_1_0.py
)- This seems not to be necessary anymore
- comment-in the
- Now you can:
- List devices with
PortableDevices.py ls
- List directory contents with
PortableDevices.py ls [Device]/directory
- Upload files with
PortableDevices.py cp source [Device]/directory
- Download files with
PortableDevices.py get [Device]/directory target
- List devices with
This software is licensed under the MIT license.