26

I recently bought a Nexus 4 and I would like to transfer my photos of my previous device to it. My previous Android phone used the standard USB mass storage which gave 0 problems to copy back and forth stuff, but the Nexus 4, like many other modern Android phones I suppose, uses MTP instead, which has the interesting feature of refusing to copy the original dates/timestamps of the files, using instead the date at which the files are being copied.

This is obviously a huge bummer when it comes to photos; not only because one cannot check the original date at which the picture was taken while browsing on the phone, but also because they end up completely unsorted.

Is there a way to transfer photos to a Jelly Bean Android phone that doesn't support USB mass storage preserving the original timestamps?

Things I've tried so far:

  • Transferring via USB MTP
  • ADB push (both full folders and individual files)
  • Transferring via SSH (using SSHDroid + WinSCP)
  • Uploading and downloading from Dropbox
  • Transferring a ZIP file via MTP and uncompress the file on the phone
  • Transferring from the other phone via bluetooth
  • QuickPic "fix date" function
  • Local Sync
  • Photo Date Correction
  • FTPSyncX
  • Smoke signals
  • Yelling at the phone

None of them preserved the timestamp, and this is driving me insane.

(Also, I am not rooted yet, but if the only viable way requires root I would welcome that answer as well.)

2
  • Does Android support untaring .tar files? If so, maybe you could copy a .tar file of the pictures. I don't know if the untaring would change the timestamp of the individual files or not.
    – Chance
    Dec 21, 2012 at 22:46
  • @Chance tried that before but didn't help either; the issue is nothing has privileges to write the timestamp by default, so there's nothing one can do but rooting right now.
    – Mahn
    Dec 22, 2012 at 1:19

20 Answers 20

10

You can't, this is a current permission problem (bugreport here) of Android 4.0+'s /sdcard folder if it's not using FAT32 (but FUSE).

Reason: There's a transition away from FAT32 to unified user storage for both apps and media data (using ext4) on a single file system.

We got tired of seeing OEMs include many GB of internal storage for music, while users were still running out of space for apps and data. This approach lets us merge everything on one volume, which is way better.

-- Dan Morrill, Android engineer at Google

The old FAT32 properties are emulated using a FUSE layer to be compatible with existing apps. Also: /data/ and /sdcard on Google devices starting with the Nexus 7 use a single partition only (/data/media represents the "sdcard" content and is exposed using the FUSE layer to apps).

Here's CyanogenMod's implementation of the FUSE driver if you're interested in seeing the source. Looks like setting timestamp attributes is implemented, though.

EDIT: It only works with root.

Exact reason: All files are owned by root.sdcard_rw (see here).

A caller withouth uid=0 can't call the utimensat() syscall, it fails in the VFS layer already (EPERM) for timestamps other than current:

  1. the caller's effective user ID must match the owner of the file; or
  2. the caller must have appropriate privileges.

To make any change other than setting both timestamps to the current
time (i.e., times is not NULL, and both tv_nsec fields are not
UTIME_NOW and both tv_nsec fields are not UTIME_OMIT), either condition
2 or 3 above must apply.

3
  • Thanks for the info, let's hope this is something google can and would be willing to address, because as far as I can tell the problem is not the fuse layer or the mtp protocol, but the strict privileges that were set there, which by the way appear to be pretty recent (4.2.1?) since the Photo Date Correction app posted below did seem to work with older, 4.0 fuse/mtp based devices such as the galaxy nexus.
    – Mahn
    Dec 22, 2012 at 1:15
  • 2
    Update for future readers: this remains unfixed in 4.2.2.
    – Mahn
    Feb 20, 2013 at 12:24
  • 2
    Update for even more future readers: unfixed in 6.0 marshmallow.
    – Mahn
    Dec 10, 2015 at 17:11
6

I recently came across this issue on a Nexus 5 and tried most the solutions listed here with no luck. In my case, it looks to be caused by a recognized bug with stock Android (source).

My solution was as follows - I used Windows 8.1, but no reason this wouldn't work on OSX/Linux (root is required on device however).

  1. On your PC, create a .tar.gz archive of all the files you wish to transfer.

    • I used 7zip for this - It's worth mentioning on Windows, you'll need to create the .tar archive first, then apply the .gz compression.
  2. Transfer the archive to the device using FTP, ensuring the MFMT command is used.

    • FTP Server supports MFMT on the device side. Just install and enable, no extra configuration needed.
    • On the PC, I used Filezilla - you do need to ensure Transfer > Preserve timestamps of transferred files is checked.
  3. On the device, extract the archive in a shell as root.

    • Using Terminal Emulator, first ensure you have root access by using the su command. You may need to grant access if SuperSU pops up.
    • Navigate to the directory now containing the .tar.gz archive with the cd command e.g: cd /sdcard/
    • Extract the archive using the following: tar -xvf ARCHIVE_NAME_HERE.tar.gz
    • Note: For some reason, when I extracted directly to the DCIM/Camera directory, the pictures would not show up at all in the stock gallery app. If this happens to you, I suggest you extract to a different directory and then move (not copy) the files to your camera directory. I suspect this is caused by a permissions issue. You can use the terminal or your file manager of choice to move the files.
  4. Reboot for good measure.

This allowed all the files 'date modified' attributes to remain intact, and left all photos in the correct order when viewed in the gallery app.

2
  • They show not up in the gallery because of the media index. It does not recognize your terminal operation but if you use a file manager app it reports the new moved files to the index and now they are found again. Are you sure that the ftp part is really needed? I wonder because the ftp can not change the files that are inside the tar, so why should this be important?
    – mgutt
    May 30, 2016 at 16:28
  • @mgutt I guess you're right about the FTP part not being required. I was piecing together pieces of information from other suggestion solutions and this was what ended up working for me!
    – rmorrin
    Jun 3, 2016 at 9:20
4

Check the EXIF data and see if there's a timestamp there.

If there is, Photo Date Correction will allow you to overwrite the botched file timestamp with the EXIF one, giving you back your proper sorting.

1
  • Nothing. The EXIF data is there, and the app reported to successfully have changed the timestamps when I used it, but they stayed the same; I rebooted and deleted the cache of the gallery aswell, but that didn't help. Does the app require root? It seems as if there were some sort of write protection on the timestamps that nothing is able to overcome.
    – Mahn
    Dec 18, 2012 at 19:04
4

This is a question which really trouble me a lot when come across with devices which only have MTP but not the Mass storage mode. I also have concerns about it with exactly the same reasons with Mahn.

After some testing, I have find a temp solution which maybe able to preserve the timestamp.

It makes use of the excternal sdcard / OTG card reader and also the cp command with -a the timestamp will be able to preserve. But the requirement is the phone need to be rooted.

  1. First copy the data to SDcard.
  2. Read it with memory card slot / OTG card reader
  3. use adb shell and acquire root permission (su)
  4. cp -a * the data from card to internal memory.
4

As mentioned in another answer, on devices that use FUSE for SD card emulation (such as modern Nexus devices), only root can change timestamps of files in /sdcard. Since things like MTP and ADB don't run as root, you can't preserve the timestamps with these methods. However, if your device is rooted, you can fix the timestamps with a separate step afterward.

While restoring a full backup of /sdcard from a Linux PC to my tablet, I used this command to fix all the timestamps after uploading the files with adb push:

find . | while read file; do timestamp_stat=$(stat -c "%y" "$file"); timestamp=$(date +"%Y%m%d.%H%M%S" -d "$timestamp_stat"); echo "$timestamp: $file"; adb shell su -c "touch -t $timestamp \"/sdcard/$file\""; done

This should be run from the root of the directory on the PC that corresponds to /sdcard on the device. (Or, if you uploaded something other than a full /sdcard backup, change the path in the touch command near the end. But you should run this from whatever directory on the PC corresponds to the directory in the touch command.)

The way it works is that it goes through all the files on the PC side, gets the timestamp of each, and runs a touch command as root on the device to set the timestamp of the corresponding file there.

Note that this will run a separate su command for each individual file. If you have logging enabled in your root program (e.g. SuperSU), you may want to disable that to avoid producing large numbers of log entries. And if you have your device configured to prompt for confirmation on every su request, you'll probably want to change that temporarily. (It may be possible to come up with a variation that pipes a stream of touch commands into a single root shell on the device, but the straightforward way of doing that didn't work when I tried it, and I didn't want to spend much time on it.)

I've used this with success on a Nexus 10 running Android 5.1.

2

I have the exact same issue. It seems that it's being blocked by fuse on the Nexus 4 running Stock JellyBean 4.2.1.

SYMLINKS:
/sdcard -> /storage/emulated/legacy
/storage/emulated/legacy -> /mnt/shell/emulated/0

MOUNT POINT:
/mnt/shell /dev/fuse /mnt/shell/emulated fuse \
    rw,nosuid,nodev,relatime,user_id=****,group_id=****,default_permissions,allow_other 0 0

That info was taken via an adb shell session; I presume that fuse will be in the mix for all app-level accounts.

TL;DR From the looks of it, it can't be done without rooting the phone.

2
  • 1
    My "solution" for the time being is to upload pictures from past phones one at a time in chronological order, with pauses in-between, in a different directory. Here's the Linux shell script I'm using: [old_pictures]$ for f in $(ls -1 * | sort -t _ -k 2); do adb push $f /storage/sdcard0/DCIM/Past/; sleep 3; done; If you go this route, do a test upload first to be sure you're satisfied. Also, disable Google+ Instant Upload while you're at it so you don't get "double uploads".
    – Turtle
    Dec 21, 2012 at 0:53
  • Thanks, that helps; as your for script: both mtp via windows and adb push drop the connection for me after the first thousand files or so in my case, plus some files randomly end up corrupted, are you seeing the same? basically as this issue describes here: code.google.com/p/android/issues/detail?id=35185 (perhaps I should make a separate question, since this is not directly related with the timestamps themselves. Gotta love mtp though)
    – Mahn
    Dec 22, 2012 at 1:02
2

If you use the Google Photo app and you want your file to be listed in the right order there's a solution.

The background of the issue

This is an Android Bug. It does not allow non-root user to change the modification date of files (https://code.google.com/p/android/issues/detail?id=18624 since the introduction of multi-user / sandbox with FUSE filesystem). And does not preserve the timestamp when copying files with MTP protocol (https://code.google.com/p/android/issues/detail?id=92635).

The workaround for Google Photo users

Photos are ordered using the EXIF information if available, so you can just use any manners of setting the right EXIF data to them. Any camera should set this automatically for you, just make sure the date/time is correct in them.

For videos or if you do not want to set the EXIF data just go to https://photos.google.com/ and upload your video / photos from there. It preserve the modification timestamp you have on your computer and since it is synced with your device you'll see the photo in the app, correctly sorted, as soon as you are done with the upload.

1

Use a synchronization tool like e.g. FolderSync, which should take care for timestamps accordingly. Synchronization tools should be specialized in handling all aspects of really maintaining synchronous copies -- including time stamps, of course.

10
  • I tried a couple of sync tools, but none synced the timestamp, because I guess there is some sort of protection. Thanks for the answer though.
    – Mahn
    Dec 18, 2012 at 19:08
  • Did you try FTPSyncX Trial? Not the most sophisticated look maybe (the dev is no designer). But I use the Pro for about a year already, and it syncs timestamps fine via SFTP/SSH (the only protocol I use -- the app can handle more).
    – Izzy
    Dec 18, 2012 at 19:36
  • I'll check it, but considering SSHDroid didn't work for me I guess I won't get the timestamps with it either.
    – Mahn
    Dec 18, 2012 at 20:51
  • I almost bet it will. I still remember how hard that part was for the dev -- we sat hours on Skype discussing the issue :) There was that ugly time problem on Windows, which sometimes reported things wrongly... Oh, getting OT :) Simply try it, cannot hurt, right? And let us know how it worked out...
    – Izzy
    Dec 18, 2012 at 21:12
  • Nothing. FTPSyncX Trial as a client on the phone, freeSSHd as a server on my laptop, I'm able to connect and sync files via STP/SSH, but the timestamp of pictures transferred to the phone is still getting overwritten to the current date.
    – Mahn
    Dec 20, 2012 at 9:33
1

PRESERVING DATE MODIFIED ON NEXUS DEVICE --- NO ROOT NEEDED ---

  • From Android to PC: Use MTP
  • From PC to Android: Use Droid Explorer

cheers.. :)

it preserve Date Modified. I dont know how Droid Explorer does it. but it just works.

make sure USB Debuging checked before use Droid Explorer.

um.. there's one limitation though.. Droid Explorer only can transfer files, not folders.

  • with Droid Explorer, copy files into android phone on some specific folder
  • then with file manager inside android, move those files into folder we want, do not use copy because copy will alter date modified while cut doesn't.
2
  • Droid Explorer requires ROOT, doesn't it?
    – AntonK
    Jun 23, 2014 at 16:28
  • @AntonK Yes Droid Explorer needs Root to preserve the timestamp. If Root is not available it will overwrite the date: maxrev.de/…
    – mgutt
    May 30, 2016 at 20:41
1

Use PTP instead of MTP when connecting your phone by USB. It works for me, I use a Samsung Note 4 connected to Ubuntu 14.04 machine. However, connecting as PTP only allows copying of pictures/images. All other methods od copying files (bluetooth, WIFI, file manager) into an external drive will change the date.

1
  • I tested that with Windows 10 and a Note 3 using CM 12.1 (Android 5.1.1). I moved the files (the only way windows allows preserving) but it did not preserve the timestamps. :(
    – mgutt
    May 30, 2016 at 16:47
1

You can use adb

  1. Enable Developer mode on mobile.

  2. Enable USG debugging on mobile.

  3. Install ADB on your laptop.

  4. Connect your mobile to your laptop using USB.

  5. Open your laptop terminal and login to your mobile using below commands

    adb devices adb shell

  6. Find the exact path where you want to put your files.

  7. Exit adb shell using the command exit.

  8. Use below command to push files to from your laptop to mobile without any metadata (created/modified time) being affected

    adb push source_path target_mobile_path

You can push folders and multiple files using the adb push command in one go.

You can use the same procedure and command adb pull source_mobile_path target_laptop_path to copy files from mobile to laptop without affecting dates.

0

My solution to preserve modification date during file copy on Android device with MTP:

Tested on LG G2 stock (without root), Andorid 4.4.2 and HTC one M7, Andorid 4.4.2:

  1. Network share of the folder to copy on the computer (Win 8)
  2. Use SyncMe Wireless to copy files from computer to device

As far as I can see, the modification dates are fully preserved!

0

Backup solution using "SanDisk Memory Zone" to preserve timestamp date. copy/moving files from Android device to external SDCard - Tested on Samsung Note 2, Note 3 and Mini SIII

Just backup your photo files to SDCard and move the card to other Android, PC, Apple or other device - if not used to backup your photo files, follow this simple 8 steeps instructions"

  1. Search on Google Play and install "SanDisk Memory Zone".
  2. Start the App and wait for index file to finish.
  3. Select Backup/Restore and change or mark settings.
  4. Select Memory Card destination and what to backup (contacts, sms, photos, music, etc).
  5. Verify required and available capacity, and go on CONTINUE botton.
  6. Wait for the backup to complet.
  7. Now you have a copy of the files in your SDCard on ".memoryzone_backup/files/1"
  8. Now you can move your SD Card files like photos to your Windows, Linux or other Android device preserving original Timestamp.
1
  • copying files to external SD-cards doesn't cause the problem with the modification timestamp
    – AntonK
    Jun 23, 2014 at 16:37
0

Quick and easy solution: simply use a PC or Mac to copy the files from the old SD Card (or PC) to the new SD Card. Use a PC/Mac with an SD Card reader/writer (there are USB-to-SD Card converters) which sees the card as a FAT32 USB storage. When you're done copying, re-insert the new card in your phone and reboot.

0

I moved to a Moto X 2014 and I had this problem.

I tried many things as well, a solution seemed to be "Motorola Migrate" to synchronize with WiFi two phones (an old gingerbread backflip). In the gallery, the situation was good (even in details), but strangely in file manager the date was changed, and after few hours even the gallery also shown the transfer date.

The workaround, if the files are not too many, could be manually copy one by one, changing each time the date and hour on the phone.

0

I have a Nexus 4 and had the same issue with time-stamp and photos (indeed all the files).

Here are the command lines (with a rooted phone) I used, thanks to a post on Ubuntu:

sudo apt-get install android-tools-adb

(on Ubuntu if Android SDK is not installed)

adb devices
cd /media/my_backup_folder_where_i_put_a_folder_with_all_my_data_named_"savandroid"_in_it

In order to go in my folder "backup" which contains the folder "savandroid"

adb root
adb push savandroid /sdcard

All files and folder that are in "saveandroid" are sent to SD card worked nicely with all time-stamps correct!

Note: On Cyanogenmod I had to select root for "apps and adb" in developers menu. By default it's only set on apps.

0

I will add my solution that worked on Ubuntu

First install simple-mtpfs and install fuse

cd ~
mkdir myphone
simple-mtpfs ~/myphone

Now you have your phone folders mounted on this directory, you can use rsync -t , or cp -p to copy the pictures and the created/modified/accessed times will not be changed.

Work for me :)

1
  • In the terminal, while mounted with simple-mtpfs, timestamps appear as preserved. But when accessing the files in the phone, the timestamps seem to be all reset. May 1, 2018 at 11:14
0

To copy files from your Android to your PC keeping timestamps:

adb shell tar c -C /storage/emulated/0/XXX . | tar xv

To restore them back to the Android:

tar c . | adb shell tar xv -C  /storage/emulated/0/XXX 

This works by creating a tar file within the device, that is immediately extracted on your host, and viceversa.

The "v" lets you see the name of the file being copied.

Of course this assumes that you have "adb" installed, that the phone has USB debugging enabled, and that you already validated the debugging certificate.

sudo apt install adb
-1

Try app "Bluetooth File Transfer" it preserves the modified date with move. And I believe with copy too but try with one file/ folder first to make sure. It can also explore the other device via bluebooth.

1
  • Providing a link to apps that you recommend would make this a more useful answer. Apr 19, 2015 at 23:52
-1

Use SyncMe Wireless and network share. The timestamps are preserved and the sync is quick. I was able to back up without a computer to SD Card in Kingston MobileLite Wireless in 20 minutes, re-sync instant.

2
  • Can you link this app? Jun 14, 2015 at 15:55
  • I could only find the link for SyncMe Wireless, but not "Network share", unless you actually meant it is a single app. Also provide the short summary of the app and the steps to do it if possible.
    – Andrew T.
    Jun 26, 2015 at 1:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .