72

I'm moving files on the server from one directory to another using the file manager. Is there a way to preserve file creation date/time (when it was first added to server)? Someone suggested SSH, but I'm not very familiar with it. Does anyone have some good instructions on this?

Brad Werth
  • 17,411
  • 10
  • 63
  • 88
Kakenx
  • 1,315
  • 3
  • 18
  • 34
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww May 27 '18 at 22:14

3 Answers3

125

Use scp with the -p option.

 -p      Preserves modification times, access times, and modes from the original file.

Example command copying a file from local to remote server:

scp -p /home/mylocaldata/test.txt remote.example.com:/home/remote_dir

Note that this will not preserve user and group only permission flags (rwx and such).

Nux
  • 9,276
  • 5
  • 59
  • 72
Tharanga Abeyseela
  • 3,255
  • 4
  • 33
  • 45
  • 1
    try this web site http://www.hypexr.org/linux_scp_help.php scp comes with linux (most of the time). just try the command shell and type scp. so command looks like this. assume i need to transferfrom /home/mydata/test.txt file to destination server x.x.x.x directory - /home/test so i use the following command with preserve permissions. scp -p /home/mydata/test.txt x.x.x.x:/home/test – Tharanga Abeyseela Nov 28 '13 at 00:19
  • I would have assumed this to be the default; so much so that I created an alias in the ~/.bashrc as so: `alias scp='scp -p'` :) – Bikash Gyawali Mar 19 '21 at 16:10
10

You can also rsync over SSH with the -t or --times option

rsync -P -e ssh -t <source> <destination>

I like to use the -P option (same as --partial --progress) because it doesn't delete all the files if you stop the transfer (or it fails) halfway through and it reports progress. See man rsync

   -t, --times
          This  tells  rsync  to  transfer modification times along with the
          files and update them on the remote system.  Note that if this op‐
          tion  is  not used, the optimization that excludes files that have
          not been modified cannot be effective; in other words,  a  missing
          -t  or -a will cause the next transfer to behave as if it used -I,
          causing all files to be updated (though rsync’s delta-transfer al‐
          gorithm will make the update fairly efficient if the files haven’t
          actually changed, you’re much better off using -t).
Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103
0

You can do this on FileZilla once you have set up the ssh server on the remote machine: there is a preserve timestamp option on the Transfer menu.

Steve J
  • 59
  • 4