in reply to Re: Re: using $ftp->mdtm($file)
in thread using $ftp->mdtm($file)

stewartski,
Perhaps you should take a look at PerlTidy as good indention really helps in readability and bug hunting. Since you have not shown all of the code, I do not know what $timeThen is so I will assume it is an epoch time stamp. You also do not show where $connect comes from? Are you using warnings and strictures? I have never used Net::FTP, but I would guess it should look something like this.
my $stamp; # set to appropriate epoch time stamp my @files = $ftp->ls(); chomp( @files ); for my $file ( @files ) { print "Testing file : $file\n"; if ( $file !~ /\.stm$/ ) { print "Skipping : $file is not an .stm file\n"; next; } my $mtime = $ftp->mdtm($file); die "cannot get mdtm for $file\n" if ! $mtime; print "$file last modified : ", scalar localtime($mtime), "\n"; if ( $mtime < $stamp ) { print "Removing file : $file\n"; $ftp->delete($file); print $ftp->message, "\n"; } }
Cheers - L~R

Replies are listed 'Best First'.
Re: Re: Re: Re: using $ftp->mdtm($file)
by stewartski (Initiate) on Feb 25, 2004 at 16:02 UTC
    L~R - thanks for time & patience: I take your point about indentation. I will use <code> tags in future to preserve my code layout.

    You are almost right in your assumption that $timeThen is an epoch time stamp (in fact time-(14*24*60*60) to give time in seconds 14 days ago). Also $connect is the same as $ftp in your code. I am using warnings and strictures.

    Unfortunately, even using your modified code my program still dies on the first .stm file it finds with the 'cannot get mdtm' message.

    However, if I comment out the 'die "cannot get mdtm ..."' line, I get this error message displayed (for every .stm file in the directory): "Use of uninitialized value in localtime at mdtm_test.pl at line 36."

    (Line 36 is the 'print "$file last modified ... "' line). Then it prints the time last modified as "file name last modified : Thu Jan 1 00:00:00 1970"! The epoch if not much mistaken. Obviously my .stm files have been modified since then.

    Not entirely sure what that error message is telling me but it's a start. I realise I will have to convert either the modified time into secs or the $stamp time into an epoch time stamp (possibly using POSIX strftime).

    Thanks again for your time
    Stewartski

      stewartski,
      You can't just comment out code all willy nilly. There is a problem, it told you what the problem is, you need to correct it before moving on. Now I can't guess as to what the problem is because you have not shown all the code, but it sounds like mdtm is on an operating system that does not work correctly or you are not passing it file names the process has permission to query. You will need to show more/all of your code - preferrably in readmore tags. You have me worried when you say $connect is the same as $ftp. Unless you have two concurrent FTP processes going at the exact same time in the same directory you can not interchange them like you did.

      Cheers - L~R

        Thanks L~R - at the risk of sending us both round in circles, I present the entire (short) program (as you suggest in readmore tags): This program runs fine with no error messages, but exits on the first .stm file with the "cannot get mdtm time" message.

        The script is being run from a machine running Linux, although I don't at present know what flavour/version, likewise the remote server the script is 'operating' on.

        Once again I am very grateful for your time and energy.

        Thanks
        stewartski