Recent

Author Topic: Copy File to MTP  (Read 8836 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: 2223
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: 2786
    • 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 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

ASerge

  • Hero Member
  • *****
  • Posts: 2223
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: 14204
  • Probably until I exterminate Putin.
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.
Specialize a type, not a var.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • 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 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • 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 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

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: 2223
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: 14204
  • Probably until I exterminate Putin.
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.
Specialize a type, not a var.

dbannon

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

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Copy File to MTP
« Reply #14 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... :)
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

 

TinyPortal © 2005-2018