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