Announcement

Collapse
No announcement yet.

How to maintain the file creation date when dowloading from FTP?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to maintain the file creation date when dowloading from FTP?

    How to maintain the original file creation date when dowloading from FTP? Because when I've tested it, the downloaded file takes its creation date from the current time of download and doesn't keep the original creation date.

    Thank you.

  • #2
    FTP does not keep the remote timestamp by default. First you have to retrieve the original file date from the server with FTP.GetFileInfo(). Then you can use touch to set the file date. touch is a command line utility that is from the Unix world, and is available on Windows as part of the Cygwin core utilities.

    Here is a short demonstration how to use this utility. I download a file, fetch the date/time the FTP server provides (please note that depending on the file, date and FTP server software, this info may be incomplete), and then use touch to set the timestamp accordingly.

    Code:
    [COLOR="#008000"]-- file to be downloaded[/COLOR]
    filename [COLOR="#FF0000"]=[/COLOR] [COLOR="#800080"]"dummy_file.pdf"[/COLOR];
    
    [COLOR="#008000"]-- folder where the file is to be downloaded[/COLOR]
    targetfolder [COLOR="#FF0000"]=[/COLOR] [COLOR="#800080"]"D:[COLOR="#800080"]\\[/COLOR]eSupport[COLOR="#800080"]\\[/COLOR]"[/COLOR];
    
    [COLOR="#008000"]-- full path to touch.exe[/COLOR]
    touch [COLOR="#FF0000"]=[/COLOR] [COLOR="#800080"]"D:[COLOR="#800080"]\\[/COLOR]eSupport[COLOR="#800080"]\\[/COLOR]touch.exe"[/COLOR];
    
    [COLOR="#008000"]-- perform the download[/COLOR]
    FTP[COLOR="#FF0000"].[/COLOR]Connect([COLOR="#800080"]"10.0.0.1"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"username"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"secret"[/COLOR]);
    FTP[COLOR="#FF0000"].[/COLOR]Download(filename[COLOR="#FF0000"],[/COLOR] targetfolder [COLOR="#FF0000"]..[/COLOR] filename);
    
    [COLOR="#008000"]-- get the filestamp of the remote file[/COLOR]
    FileInfo [COLOR="#FF0000"]=[/COLOR] FTP[COLOR="#FF0000"].[/COLOR]GetFileInfo(filename);
    FTP[COLOR="#FF0000"].[/COLOR]Disconnect();
    
    [COLOR="#008000"]-- set the local timestamp[/COLOR]
    timestamp [COLOR="#FF0000"]=[/COLOR] [COLOR="#0000FF"]string.format[/COLOR]([COLOR="#800080"]"-t %04d%02d%02d%02d%02d "[/COLOR][COLOR="#FF0000"],[/COLOR] FileInfo[COLOR="#FF0000"].[/COLOR]Year[COLOR="#FF0000"],[/COLOR] FileInfo[COLOR="#FF0000"].[/COLOR]Month[COLOR="#FF0000"],[/COLOR] FileInfo[COLOR="#FF0000"].[/COLOR]Day[COLOR="#FF0000"],[/COLOR] FileInfo[COLOR="#FF0000"].[/COLOR]Hour+[COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR] FileInfo[COLOR="#FF0000"].[/COLOR]Minute);
    File[COLOR="#FF0000"].[/COLOR]Run(touch[COLOR="#FF0000"],[/COLOR] timestamp [COLOR="#FF0000"]..[/COLOR] filename[COLOR="#FF0000"],[/COLOR] targetfolder[COLOR="#FF0000"],[/COLOR] SW_MINIMIZE[COLOR="#FF0000"],[/COLOR] [COLOR="#0000FF"]true[/COLOR]);
    Adapt this to fit your needs.

    Ulrich
    Attached Files

    Comment


    • #3
      Thanks Ulrich. Can we use and distribute the touch.exe freely?

      Comment


      • #4
        You can certainly use it freely, however as Cygwin is released under a GNU license, you will need to check if you can redistribute it with your product... I am not a lawyer, please check the web site for further info. On the other hand, it shouldn't be too hard to build such a tool - it just happens that I have Cygwin installed here for things like grep, this is what I use.

        Ulrich

        Comment


        • #5
          Thanks a lot Ulrich.

          Comment


          • #6
            By the way, perhaps in the next version of AMS, could we request the command file.SetAttrib to update the creation date, what do you think?

            Regards.

            Comment


            • #7
              Hi Ulrich,

              In a batch mode processing more than 100 files, I noticed that some files, the time stamp were correct but some, the hour were increased by 1, why it is not consistent?

              -- set the local timestamp
              timestamp = string.format("-t %04d%02d%02d%02d%02d ", FileInfo.Year, FileInfo.Month, FileInfo.Day, FileInfo.Hour, FileInfo.Minute);

              Thank you.
              Last edited by adeam; 10-20-2010, 08:31 AM.

              Comment


              • #8
                As the touch.exe is not working properly in my case, I've searched another version on the web and found this website.

                http://www.touchdotexe.com/

                Using the touch.exe downloaded in this website, it worked well in my batch processing. Also, I used the isodate to simplify the command.

                timestamp = " -d " .. FileInfo.DateISO;
                File.Run(touch, timestamp .. " " .. targetfolder .. filename, targetfolder, SW_MINIMIZE, true);

                FYI.

                Comment

                Working...
                X