Copying files to an mtp device(android phone in this case) using cp won't restore timestamps

When copying files from phone to PC using cp command to preserve original timestamp, it works without any issue. but doing it in reverse(PC to phone) causes an error. I ise my Pc as a backup of my phone and when i restore it, i dont want everything to be jumbled up. Here is the error log(username redacted). Distro- Manjaro XFCE

[[redacted]@[redacted]PC /]$ cp -rp /run/media/[redacted]/D/documents/photo.jpg /run/user/1000/gvfs/mtp:host=XiaomiSM6150-IDP_SN%3AE0C22BCD_d7cde9d/“Internal shared storage”/Pictures

cp: preserving times for ‘/run/user/1000/gvfs/mtp:host=XiaomiSM6150-IDP_SN%3AE0C22BCD_d7cde9d/Internal shared storage/Pictures/photo.jpg’: Operation not supported

[[redacted]@[redacted]PC /]$ cp -rp /run/user/1000/gvfs/mtp:host=XiaomiSM6150-IDP_SN%3AE0C22BCD_d7cde9d/“Internal shared storage”/Pictures/photo.jpg /run/media/[redacted]/D/

[[redacted]@[redacted]PC /]

Hello there

May want to use the touch utility to try and copy the time stamps over, remember to restart your Android phone after doing so.

touch -r <original_file> <new_file>

Would i have to do that for every single file?

Assuming you confirm it works, should be able to pass an argument to apply it to all.

It didn’t worked. Same operation not suppored error.

Use adb instead:

Copy files to the phone:

adb push --sync /local/path /remote/android/path

Copy file from the phone to local disk:

adb pull -a /remote/android/path /local/path

With -z you can enable compression. Useful for wireless.

That worked, thanks.

One more question tho, how is windows filemanager able to handle mtp so well? Are there some file manager/distro in linux that is able to do that?

No idea, does it preserve the timestamp?

gvfs-mtp is used commonly in file managers on Linux. I guess there is a problem. I would rather say that cp does not support MTP, so non-linux filesystems. You can also try mtpfs:

mtpfs -o allow_other ~/my-empty-folder

More methods: Media Transfer Protocol - ArchWiki

Yes, it does by default. Just drag and drop.

I tried with mstfs also, unable to mount the device using that command. Here is the error log.

[[Redacted]@[Redacted]PC ~]$ mtpfs -o allow_other ~/Android
Listing raw device(s)
Device 0 (VID=18d1 and PID=4ee2) is a Google Inc Nexus/Pixel (MTP+ADB).
 Found 1 device(s):
 Google Inc: Nexus/Pixel (MTP+ADB) (18d1:4ee2) @ bus 1, dev 2
Attempting to connect device
Android device detected, assigning default bug flags
Listing File Information on Device with name: (NULL)
[[Redacted]@[Redacted]PC ~]$ ls ~/Android
ls: cannot access '/home/[Redacted]/Android': Transport endpoint is not connected
[[Redacted]@[Redacted]PC ~]$ 

Thunar also reports same error (transport endpoint not connected) when opening home directory

ok so which value? Example:

LANG=C stat file                                                                         ✔ 
  File: file
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: 27h/39d	Inode: 450728      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   user)   Gid: ( 1000/   user)
Access: 2021-07-15 16:12:28.233316937 +0200
Modify: 2021-07-15 16:12:28.233316937 +0200
Change: 2021-07-15 16:12:28.233316937 +0200
 Birth: 2021-06-10 03:35:36.971406491 +0200

I can’t believe it preserve everything on windows…

It takes a while until all files are listed at the background. MTP is just slow.

Cant confirm about everything, but i did preserved timestamps.

So should i wait before using the command or after using the command?

I tried jmtpfs and go-mtpfs, both got mounted successfully and copying from the device preserves timestamps. Copying to the device however doesn’t preserves timestamps.
Jmtpfs returns error

 failed to preserve ownership: function not implemented 

While go-mtpfs doesn’t return any error