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

I am using Net::FTP. I can connect, log in, and put a file. I need also to be able to delete files. But when I invoke the delete() method, it says it can't locate it.
$ cat testDelete.pl #!/usr/bin/perl use strict; use warnings; use Net::FTP; use shipments; use constant FALSE =>0; use constant TRUE =>1; my $DEBUG = TRUE; ###################################################################### +# # returns TRUE if successful sub ftpDeleteRemoteFile($$$$) { my ($host, $user, $password, $remoteFile) = @_; my $ftp = Net::FTP->new($host, Debug => $DEBUG); if (! $ftp) { print "Cannot make FTP connection to $host: $@\n"; return FALSE; } if (! $ftp->login($user, $password)) { print "Cannot log in via FTP connection as $user to $host: " +. $ftp->message . "\n"; $ftp->quit; return FALSE; } if (! ftp->delete($remoteFile) ) { print "Cannot delete file $remoteFile from host $host\n"; $ftp->quit; return FALSE; } $ftp->quit; return TRUE; } ftpDeleteRemoteFile(getShipperHost(), getShipperUser(), getShipperPass +word(), "to/csgload/testfile1"); # Keep the perl compiler happy TRUE; The output I get is: $ testDelete.pl Net::FTP>>> Net::FTP(2.77) Net::FTP>>> Exporter(5.58) Net::FTP>>> Net::Cmd(2.29) Net::FTP>>> IO::Socket::INET(1.29) Net::FTP>>> IO::Socket(1.29) Net::FTP>>> IO::Handle(1.25) Net::FTP=GLOB(0xfdd3e0)<<< 220 Welcome to XXX FTP service. Net::FTP=GLOB(0xfdd3e0)>>> USER YYY Net::FTP=GLOB(0xfdd3e0)<<< 331 Please specify the password. Net::FTP=GLOB(0xfdd3e0)>>> PASS .... Net::FTP=GLOB(0xfdd3e0)<<< 230 Login successful. Can't locate object method "delete" via package "ftp" (perhaps you for +got to load "ftp"?) at /home/stats/csgload/bin/perl/testDelete.pl lin +e 32.
(host and username changed, obviously)

I have perl 5.8.8, and version 2.77 of Net::FTP

  • Comment on In Net::FTP, "Can't locate object method "delete" via package ftp..."
  • Download Code

Replies are listed 'Best First'.
Re: In Net::FTP, "Can't locate object method "delete" via package ftp..."
by thezip (Vicar) on Jul 11, 2008 at 21:21 UTC

    D'oh! You're missing a $ in front of:

    ftp->delete($remotefile); ^ $

    Your wish is my commandline.
      D'oh! indeed. Thanks!
Re: In Net::FTP, "Can't locate object method "delete" via package ftp..."
by tilly (Archbishop) on Jul 11, 2008 at 21:26 UTC
    You forgot the $ in front of ftp. So it is making the method call on the package named ftp, and not on your object $ftp.

    A random tip to the wise. Don't use prototypes. They really don't do what you think they do, and what they do do you almost certainly don't want.