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

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):
#!/usr/bin/perl use strict; use warnings; use Net::FTP; use POSIX qw(strftime); my $SERVER=xxx; my $USERNAME=yyy'; my $PASSWORD='zzz'; my $DIRECTORY='_test_data'; # a regexp my $filemask='\.stm$'; my $timeNow=time; # substract 14 days * 24 hours * 60 mins * 60 secs $timeNow-=(14*24*60*60); my $timeThen=strftime "%Y%m%d%H%M%S", localtime($timeNow); print "timeNow = $timeNow \n"; print "timeThen = $timeThen \n"; print "filemask = $filemask \n"; my $ftp = Net::FTP->new($SERVER, Passive => 1) || die "Cannot connect: + $!\n"; $ftp ->login($USERNAME,$PASSWORD) || die "Cannot login: ".$ftp->mes +sage." \n"; print "Connected \n"; $ftp->cwd("$DIRECTORY"); print "Changed directory\n"; 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 type 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 < $timeThen ) { print "Removing file : $file\n"; $ftp->delete($file); print $ftp->message, "\n"; } } print "quitting"; $ftp->quit();
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

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: using $ftp->mdtm($file)
by Limbic~Region (Chancellor) on Feb 26, 2004 at 13:51 UTC
    stewartski,
    A quick cursory glance at your code doesn't reveal any immediate problem. So now I can only offer you possibilities.
    • See if it behaves the same way on a different server
    • See if it behaves the same way in active mode
    • Change $ftp->ls() to $ftp->dir() and manually parse the time stamp
    • Modify the mdtm sub from Net::FTP and possibly provide a bug fix.

    I will explain the last part now. You want to temporarily change the mdtm sub to the following:

    sub mdtm { my $ftp = shift; my $file = shift; return $ftp->_MDTM($file) || undef; }
    This won't fix anything - this is strictly to see what the stamp looks like. If you can subsequently modify the original code to properly parse it great - send in a patch. If not, post a new SoPW question saying how can I convert "X" into epoch time stamp.

    Cheers - L~R