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

Hello, I am a beginner to Perl but I wrote some code to ftp files from an ftp server to the local machine. I did this using the Win32::Internet module. As shown below, I use the List method to get the list of files in a folder on the FTP server. Then I use the mtime property to find out when the file was modified last.
@files = $ftp->List($sFileNamePattern, 3); foreach my $file (@files) { if (CheckDTS($file->{'mtime'}) == 1) { push(@aGoodFiles, $file); } }
The date/time stamp returned is fine except the seconds are always 00. I have a different files on the FTP server with different second values but the mtime property is always 00. It like the seconds are getting dropped. Has anyone ever heard of this? Any help would be greatly appreaciated. Thanks.

Replies are listed 'Best First'.
Re: mtime method dropping seconds
by roboticus (Chancellor) on Apr 13, 2010 at 11:47 UTC

    Anchor:

    Note: If you're trying to get the date/time from the FTP server, you'll want to be aware that the list format on FTP servers isn't standardized, so you won't be able to get that information for all FTP servers. (I'm looking at you MVS! I can only get the date that I last accessed a file, no times, no create/modify date...)

    ...roboticus

Re: mtime method dropping seconds
by Marshall (Canon) on Apr 13, 2010 at 05:50 UTC
    I don't know what CheckDTS() does. What happens if you just print the name and mtime?:
    my @files = $ftp->List("*.*", 3); foreach my $file (@files) { print $file->{'name'}, " ", $file->{'mtime'}, "\n"; }
      Thanks for the reply.

      I put in the print statement and ran the program. I had one file on the FTP server with a date/time of 4/9/2010 4:35:13 (EST) and this gets printed out: 0,35,20,9,4,2010

      I understand the 20 for the hours is there because its getting the date/time in GMT but I don't know why the seconds is zero. Its weird.
        This is pretty weird. Instead of using Win32::Internet, perhaps Net::FTP will give better results? This is available as an Active State module if you are using that flavor of Windows Perl. The basic idea is the same but the method names are a bit different. $ftp->mdtm ( FILE )...Returns the modification time of the given file.

        Other thoughts, ftp is a standard program on Win XP. At the command prompt, type "FTP" and hack around with that to get connected and list the remote directory. If that can show the seconds info from that server, then it is very likely that some Perl module can do it to. If not, then I am out of ideas for the moment.

        Well I guess one more FTP way is to use the FireFTP plugin to Firefox. I use it exclusively for my interactive FTP needs nowadays (instead of the command line). It is an impressive add-on.

        Update: I just logged into one SFTP site and there aren't any seconds, minutes is all I get. So, it may very well be that that's all that there is! I see a post from roboticus about this.