On 3/10/06, Nath, Alok (STSD) <[EMAIL PROTECTED]> wrote: > Hi, > When I try to retrieve the timestamp from a ftp folder I get > this error message : > >> Can't call method "mtime" on an undefined value at func.pl > line 69 > > but the same works in my local machine. > > My motive is to read the timestamp for each files in the remote > folder. > > Can somebody point out what is wrong exactly or any alternative > ?? > > Please help !! > > ~Alok > > { > my ($host, $ftpDir) = @_; > my $user = "ftp"; > my $pass = ""; > > my $ftp = Net::FTP->new($host) or die "Could not ftp to host: $host: > [EMAIL PROTECTED]"; > $ftp->login($user, $pass) or die "Could not login as $user/$pass\n"; > $ftp->binary; > $ftp->hash; > > # Show the ftp directory contents and the timestamp > foreach ($ftp->ls($ftpDir)) { > print "file = $_\n" ; > > $file_date = ctime(stat($_)->mtime);
File::stat::stat() is just a wrapper for Perl's built-in stat(). If you pass it a string, it assumes that string is a path name. if it starts with '/', it's an absolute path, otherwise it looks for ./$pathname. Your list of files to stat is on a remote server that must be accessed by a special protocol (in this case FTP), but you haven't given stat() any information about how to find that file. You've just given it a string which it assumes, rightly, should be a file on the local file system. In order to stat the file, you would have to get it first. Fortunately, Net::FTP includes the mdtm() method. `perldoc Net::FTP` for the details. HTH, -- jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of β will give rise to dom!