Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Don't ask to ask, just ask
 
PerlMonks  

In Net::FTP, "Can't locate object method "delete" via package ftp..."

by tgeliot (Initiate)
on Jul 11, 2008 at 20:59 UTC ( #697086=perlquestion: print w/ replies, xml ) Need Help??
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
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://697086]
Approved by friedo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2013-05-18 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (393 votes), past polls