Lazarus

Programming => Operating Systems => Windows => Topic started by: bambamns on February 24, 2019, 11:37:54 am

Title: Copy File to MTP
Post by: bambamns on February 24, 2019, 11:37:54 am
Hi,

Is it possible to copy local files from PC to MTP device (e.g Android phone) ?

FileUtil.CopyFile and Windows.CopyFile can't do it.

As I found , it can be done with Copy file to clipboard and Paste it from, but I can't found Lazarus code to do it.

Can it be done (anyway) ?

Thx
Title: Re: Copy File to MTP
Post by: ASerge on February 24, 2019, 07:21:17 pm
Is it possible to copy local files from PC to MTP device (e.g Android phone) ?
It's complicated. In short, you need to use the Windows Portable Devices API (https://docs.microsoft.com/en-us/windows/desktop/wpd_sdk/wpd-application-programming-interface).
Later I will make an example of, and while engaged in the translation of portable API for FPC.
Title: Re: Copy File to MTP
Post by: bambamns on February 26, 2019, 03:34:24 am
Good news - Example will be helpful

Thank you
Title: Re: Copy File to MTP
Post by: dbannon on February 26, 2019, 05:33:24 am
I concluded this would be quite hard on Linux, the MTP protocol not really a file system. I'd love to see your demo ASerge, especially if its cross platform  :D

Cannot be impossible, the GUI filemangers all do it but .....

Davo
Title: Re: Copy File to MTP
Post by: ASerge on February 26, 2019, 10:15:20 am
This is not a cross-platform example because I only know the windows api.
Very long .h file, so I only translate some things to get the demo (attached)
Title: Re: Copy File to MTP
Post by: Thaddy on February 26, 2019, 01:09:30 pm
Foe linux you can use libmtp with the same functionality.
Title: Re: Copy File to MTP
Post by: dbannon on February 28, 2019, 02:33:16 am
Quote
Foe linux you can use libmtp with the same functionality.

OK, do you know if there exists already some pascal bindings ?  I'd really like to see it work.....

Wow, it comes with some nice docs too, and C examples .....

Davo
Title: Re: Copy File to MTP
Post by: dbannon on February 28, 2019, 03:36:53 am
http://www.bakooa.com/libmtp-pascal/

The web page is not in English, perhaps French ?  (please forgive my abysmal ignorance).

Code has not been touched since 2010 but looks to be clearly written ......

very interesting ....

Davo
Title: Re: Copy File to MTP
Post by: bambamns on March 01, 2019, 04:04:55 am
@ASerge

Thank you.

This is good example for folder listing , but I still cannot find a way to copy to and from a mobile device.

Am I missing something, because I can't find in uWrapper copy or something like copy to use ?

Thank you again.
Title: Re: Copy File to MTP
Post by: bambamns on March 01, 2019, 04:14:23 am
I found on stackoverflow :
Quote
You can use MOUNTVOL command to mount the USB drive, identified by its GUID, on a specific mount point, independently of the available drive letters.

 MOUNTVOL C:\XOOM \\?\Volume{a000351d-dbaa-11e0-bdaa-020255061358}\

and then

 copy file.ext c:\XOOM\directory\file.ext


It looks it can be done, but I can't do it with GUID's I have found on my PC.
Title: Re: Copy File to MTP
Post by: ASerge on March 01, 2019, 07:13:53 pm
Quote
You can use MOUNTVOL command to mount the USB drive, identified by its GUID, on a specific mount point, independently of the available drive letters.
MOUNTVOL is an NTFS mount point tool. MTP is a media transfer protocol that is too far from NTFS. Specify what type of connection you want to use.
Title: Re: Copy File to MTP
Post by: bambamns on March 02, 2019, 01:21:55 pm
Finally I have wrote a Power Shell script and convert it to exe so it can be run with TProcess.

Major guidelines are PS script :
 - make new object as a com shell application
 - map Android with NameSpace(0x11)
 - map file and folder to copy
 - use CopyHere to copy file from and to Android

Helpful links :
PowerShell MTP https://blog.daiyanyingyu.uk/2018/03/20/powershell-mtp/ (https://blog.daiyanyingyu.uk/2018/03/20/powershell-mtp/)
PS2EXE https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-GUI-Convert-e7cb69d5 (https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-GUI-Convert-e7cb69d5)

Thanks to all for help
Title: Re: Copy File to MTP
Post by: Thaddy on March 02, 2019, 02:16:48 pm
MOUNTVOL is an NTFS mount point tool. MTP is a media transfer protocol that is too far from NTFS. Specify what type of connection you want to use.
Well, the library I mentioned (libmtp) also implements MTP on top of NTFS .... I have just not seen Pascal headers for MTP.
MTP is a protocol, not a filesystem.
Title: Re: Copy File to MTP
Post by: dbannon on January 18, 2021, 12:31:09 pm
OK, a 12 month old thread but a very good one ....

ASerge, I was wondering if you have further developed your slick Windows MTP interface posted further up this thread ?

Its pretty neat, works perfectly at what it does do but with my very limited knowledge of Windows API, not something I can develop. I would really like to be able to copy a file to a 'Device', bring back one back from a Device or delete a file there.

Davo
Title: Re: Copy File to MTP
Post by: ASBzone on January 18, 2021, 05:07:44 pm
OK, a 12 month old thread but a very good one ....

Davo

You mean 24 month old thread... :)
Title: Re: Copy File to MTP
Post by: dbannon on January 19, 2021, 01:24:07 am
You mean 24 month old thread... :)

yep, you are right.  Maybe I am trying to make out 2020 did no exist ?

Davo
TinyPortal © 2005-2018