Recent

Author Topic: Copy File to MTP  (Read 1725 times)

bambamns

  • Full Member
  • ***
  • Posts: 223
Copy File to MTP
« 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
« Last Edit: February 24, 2019, 11:42:00 am by bambamns »
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

ASerge

  • Hero Member
  • *****
  • Posts: 1255
Re: Copy File to MTP
« Reply #1 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.
Later I will make an example of, and while engaged in the translation of portable API for FPC.

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: Copy File to MTP
« Reply #2 on: February 26, 2019, 03:34:24 am »
Good news - Example will be helpful

Thank you
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

dbannon

  • Hero Member
  • *****
  • Posts: 571
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Copy File to MTP
« Reply #3 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
Lazarus 1.8, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

ASerge

  • Hero Member
  • *****
  • Posts: 1255
Re: Copy File to MTP
« Reply #4 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)

Thaddy

  • Hero Member
  • *****
  • Posts: 7991
Re: Copy File to MTP
« Reply #5 on: February 26, 2019, 01:09:30 pm »
Foe linux you can use libmtp with the same functionality.
Hamlet 1.4 (nothing wrong with the Danish, btw)

dbannon

  • Hero Member
  • *****
  • Posts: 571
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Copy File to MTP
« Reply #6 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
« Last Edit: February 28, 2019, 02:37:59 am by dbannon »
Lazarus 1.8, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

dbannon

  • Hero Member
  • *****
  • Posts: 571
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Copy File to MTP
« Reply #7 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
Lazarus 1.8, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: Copy File to MTP
« Reply #8 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.
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: Copy File to MTP
« Reply #9 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.
« Last Edit: March 01, 2019, 06:07:09 am by bambamns »
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

ASerge

  • Hero Member
  • *****
  • Posts: 1255
Re: Copy File to MTP
« Reply #10 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.

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: Copy File to MTP
« Reply #11 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/
PS2EXE https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-GUI-Convert-e7cb69d5

Thanks to all for help
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

Thaddy

  • Hero Member
  • *****
  • Posts: 7991
Re: Copy File to MTP
« Reply #12 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.
Hamlet 1.4 (nothing wrong with the Danish, btw)