Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

How do I preserve file times when using Net::FTP?

by javze (Novice)
on Feb 28, 2001 at 20:33 UTC ( #61344=categorized question: print w/replies, xml ) Need Help??
Contributed by javze on Feb 28, 2001 at 20:33 UTC
Q&A  > files


I'm using Net::FTP to download some files and I would like to preserve the times of the files I get from there. Ideas?

Answer: How do I change the modification time of a file?
contributed by merlyn

I believe if you wrap your request into an LWP::Simple mirror call instead (using an FTP URL), the mirror code correctly sets the time stamp, which means that there's some code in there somewhere to consistently understand the remote timestamp. Setting the timestamp locally is trivial: use the utime operator.

Answer: How do I change the modification time of a file?
contributed by fundflow

I had similar problem and addressed it via a script: savetime / loadtime. It will be helpful for you if you download from one of your own machines.

For your need, you will run it once on the FTP server to save the times and you run it localy to restore the times after the transfer.

Answer: How do I preserve file times when using Net::FTP?
contributed by Anonymous Monk

To accomplish this without using LWP you can do:

$mod_time = $ftp->mdtm($remote_file);
$resp = utime($mod_time,$mod_time,$local_file);
This should work on everything but FAT Win32.

Please (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (3)
    As of 2020-10-31 23:39 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (291 votes). Check out past polls.