Net::Ftp->mdtm() returns empty 
Author Message
 Net::Ftp->mdtm() returns empty

I've got a script that updates certain files on a remote computer if the
corresponding files on my local workstation are newer (i.e.,
last-modified time more recent). I am using Net::Ftp (the most current
version) successfully to log on, navigate directories, and upload files.
However, when I try to check the last-modified time of a remote file
using  Net::Ftp->mdtm(), it always returns undef, even when the file is
present and non-zero-length on the remote machine. Can anyone explain
this?

My code:

#!/usr/local/bin/perl -w
# no taint-checking because I'm the only one who uses this script

use strict;
use Net::FTP;
use Net::Telnet;
use Carp;


print "Enter user ID for Web server: ";
chomp(my $uid = <STDIN>);

print "Enter password: ";
system "stty -echo";
chomp (my $pwd = <STDIN>);
system "stty echo";

my $server = 'address.omitted.for.security';
my $target_dir = '/usr/local/apache/cgi-bin';
print "\nLogging on....\n";
my $ftp = Net::FTP-> new ($server) or croak "FTP connect failed: $!\n";

$ftp->login($uid, $pwd) or croak "Login failed: $!\n";
$ftp->cwd($target_dir)
        or croak "Could not change remote directory to
$target_dir:\n$!\n";
chdir $target_dir or croak "Could not change local directory to
$target_dir:\n$!\n";

{
        croak "$file not found in $target_dir\n" if ! -e $file;
        my $mod = -M $file;

        ###      This is where the problem is:     ###
        ### $ftp->mdtm($file) always returns undef ###
        my $rmod = (defined($ftp->mdtm($file)) ? $ftp->mdtm($file) : 0);

        my $status = $file.":\n  local last-modified time: $mod.\n";
        $status .= "  remote last-modified time: $rmod.\n";
        print $status;
        if ($rmod < $mod)
        {
                print "  Sending $file....\n";
                $ftp->delete($file.'.bak');
                $ftp->rename($file, $file.'.bak')
                        or croak "  Unable to back up remote copy ($!);
upload canceled.\n";
                if (!$ftp->put($file))
                {
                   carp "  Failed to upload '$file': $!\n";
                   $ftp->rename($file, $file.'.bak')
                           or croak "  Not only that, I couldn't rename
the backup file!\n\n";
                }
        }

Quote:
}

--

Janet Goldstein, Sr. Programmer/Analyst II
Center for Inherited Disease Research
Johns Hopkins University, Baltimore, Maryland



Mon, 05 May 2003 03:00:00 GMT  
 Net::Ftp->mdtm() returns empty

Quote:

> I've got a script that updates certain files on a remote computer if the
> corresponding files on my local workstation are newer (i.e.,
> last-modified time more recent). I am using Net::Ftp (the most current
> version) successfully to log on, navigate directories, and upload files.
> However, when I try to check the last-modified time of a remote file
> using  Net::Ftp->mdtm(), it always returns undef, even when the file is
> present and non-zero-length on the remote machine. Can anyone explain
> this?

This will happen if the server you are connected to does not support
the MDTM comand. You can verify this by looking at $ftp->message
or turning on debug with $ftp->debug(1) and looking at the protocol
trace on STDERR.

Graham.



Mon, 05 May 2003 03:00:00 GMT  
 Net::Ftp->mdtm() returns empty

Quote:

> I've got a script that updates certain files on a remote computer if the
> corresponding files on my local workstation are newer (i.e.,
> last-modified time more recent). I am using Net::Ftp (the most current
> version) successfully to log on, navigate directories, and upload files.
> However, when I try to check the last-modified time of a remote file
> using  Net::Ftp->mdtm(), it always returns undef, even when the file is
> present and non-zero-length on the remote machine. Can anyone explain
> this?

I ran into this myself. The simple answer is, not all FTP servers
support the MDTM command. You'll need to fake it out by parsing the
directory listing yourself.

-- Dave Tweed



Mon, 05 May 2003 03:00:00 GMT  
 Net::Ftp->mdtm() returns empty

Quote:

> when I try to check the last-modified time of a remote file
> using  Net::Ftp->mdtm(), it always returns undef, even when the file is
> present and non-zero-length on the remote machine. Can anyone explain
> this?

I can confirm that I am successfully using $ftp->mdtm in an application
at work, running under perl-5.6.0 with the latest Net::FTP. It seems
likely that not all ftp servers would support it, though, in which case
I would expect Net::FTP to return undef. Perhaps you should try running
a different ftpd to see if that gives you better results.

Alternatively, can you see the mtime if you ftp in by hand, and do an
ls? If so, perhaps you can work around the problem by using the ls() or
dir() methods, and parsing the desired information from the result.

Hugo



Mon, 05 May 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Object inspector vs. coded in Delphi editor problem

2. Net::FTP->mdtm(file) broken?

3. $ftp->put stores empty file (Net::FTP)

4. Net::FTP mdtm method

5. wrong date from Net::FTP mdtm

6. Decimals in DB tables ?

7. ISO - pascal compiler for dos

8. FTP->mdtm question (is this implemented?)

9. Net::FTP $ftp->pwd() undef??

10. Net::FTP examples ftp->quit hangs

11. Net::FTP ftp->ls() stopped working

12. Net::FTP $ftp->pwd() undef??

 

 
Powered by phpBB® Forum Software