Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Preserving timestamps with Net::FTP

by IraTarball (Monk)
on Jun 25, 2001 at 22:47 UTC ( #91385=perlquestion: print w/ replies, xml ) Need Help??
IraTarball has asked for the wisdom of the Perl Monks concerning the following question:

I am lost.
I have a script that uses Net::FTP to copy files to a farm of webservers. My problem is that the timestamps on the files is being changed to the current time when they are moved out. This makes using time stamp comparison difficult and I end up copying out an entire tree every time instead of just the new files.

Everything is running with Perl 5.6.1 on W2K servers.

Does anyone know how I can maintain the timestamp across Net::FTP?

Thanks,
Ira

"So... What do all these little arrows mean?"
~unknown

Comment on Preserving timestamps with Net::FTP
Re: Preserving timestamps with Net::FTP
by runrig (Abbot) on Jun 25, 2001 at 23:45 UTC
    If $ftp->mdtm() is not working for you, why not rename the files when you are done retrieving the file on the remote system, to e.g., "$oldfilename.done". Then you know you've already got it.
      That's an interesting idea. I would have to rename it file.oldtime though since the idea is to be able to do daily updates to the website from a local source. It would just be cleaner if I could preserve the time on the file attributes so that mdtm() worked.

      Thanks,
      Ira

      "So... What do all these little arrows mean?"
      ~unknown

Re: Preserving timestamps with Net::FTP
by RhetTbull (Curate) on Jun 25, 2001 at 23:48 UTC
    Try this:
    #get the modification time of the remote file #assuming $ftp is a Net::FTP object my $mtime = $ftp->mdtm($file); #download the file $ftp->get($file); #set the time of the local file # (assumes $file is also the local file name) utime $mtime, $mtime, $file;
    Regards,
    Rhet

    Update: I think I may have misunderstood your question. If you are wanting to change the time on the remote files (e.g. you are using Net::FTP to upload them to remote servers) then I'm not sure how to do it. However, one solution (kludge) could be to upload the files to the remote machines then change the time on all the local files to the current time:
    my $now = time; utime $now, $now, @localfiles;

    Update #2: Another solution (also a kludge but it would work) would be to keep a logfile for each machine with the filenames and times. Then you could just parse the logfile and compare to your local files to see what needs to be uploaded.

      Ahh, but I'm 'put'ting the file, not 'get'ting it. So I can't do a utime on the file without executing a remote command, which I'm really trying to avoid for other reasons.

      "So... What do all these little arrows mean?"
      ~unknown

Re: Preserving timestamps with Net::FTP
by btrott (Parson) on Jun 26, 2001 at 00:51 UTC
    I know this is not really what you're asking, but rsync handles this perfectly. Not only does it set the correct time stamps for you, but it uses a more sophisticated algorithm to determine "what has changed" that it needs to push to the remote server.

    If you have ssh (with SSH-2 protocol support) installed on all of your servers, you could also use (bias :) Net::SFTP, which, in addition to providing secure transfers, will automatically set the time stamps correctly.

      If only I were on *NIX. :-(
      No ssh but that may have to happen. There is an rsync like thing called robocopy that I'm looking into but it might create other problems.

      "So... What do all these little arrows mean?"
      ~unknown

        I haven't tried it but rsync might work with with cygwin. I know that it is possible to get the OpenSSH server working with cygwin. It's probably a lot more effort to get rysnc, cygwin, etc. playing nicely together but might work as a last resort.
Re: Preserving timestamps with Net::FTP
by jorg (Friar) on Jun 26, 2001 at 00:56 UTC
    Isn't this something that would best be configured in your FTP daemon ?
    I know some *nix daemons can be configured to preserve things like access permissions and original timestamp of the file. It is up to the client to use the correct servercommands to do this.

    Jorg

    "Do or do not, there is no try" -- Yoda
Re: Preserving timestamps with Net::FTP
by kschwab (Priest) on Jun 26, 2001 at 05:36 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://91385]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-08-28 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls