Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've noticed that whenever I get or put a file using Net::FTP, it sets the timestamp on the destination file to be the current time, not the timestamp of the original file. Is there any way I can make Net::FTP maintain the timestamp from the original file, or do I have to set the timestamp manually?

Replies are listed 'Best First'.
Re: Net::FTP changes timestamps
by tcf03 (Deacon) on Feb 16, 2005 at 00:24 UTC
    From a quick read of the Net::FTP docs, you can do a listing and a mdtm (FILE) and you would have to set the timestamp from the return value of that.
      So you can't get Net::FTP to not change the timestamp of the file? I can fix it manually the way you suggest, but I also have to put files onto the remote machine, and it's a really old Unix whose ftp server doesn't support the quote command, so I don't know how I could fix the timestamps on files that I put on the remote machine.
        Net::FTP is not magic. Try the same steps using a plain command line FTP client and you'll see that changed timestamps are normal for FTP. Doing a 'put' or 'get' only transfers the file and does not update file time on the receiving end. Plain FTP servers and clients just slap the current time onto the transferred file.

        Some FTP servers and clients allow an extension to the MDTM command to allow you to set the remote file's timestamp as a separate step after uploading the file. But if the FTP server is ancient it probably doesn't support that command.

        When receiving a file locally you must also get and process the remote directory listing and extract the timestamp to be set. I'm not sure if module File::Listing will help you with the output from dir() but you could look at it.