m.lochhead m.lochhead - 6 months ago 24
Perl Question

Perl: Can't call method "put" without a package or object reference at ./redirect line 25

I am trying to have this program take a file from the current server i am working on an put a copy of it under a different folder on another server. I am continuously getting this error

Can't call method "put" without a package or object reference at ./redirect line 25.
I appreciate all help. Here is my program:

#!/usr/bin/perl
use POSIX qw(strftime);
use Net::FTP;


($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime();
my $bdate = sprintf("%02d%02d%02d", $mon+1, $mday-7,$year-100);
my $edate = sprintf("%02d%02d%02d", $mon+1, $mday-1,$year-100);


my $host = "xxx.xxx.xx.xxx";
my $userid = "username";
my $passwd = 'p@ssword';
my $s = Net::FTP->new($host, Debug => 0);
my $login = $s->login($userid, $passwd);

my $path = "/home/username/homdata_percentage_vs_pn/Missing_Neighbor_030716-031316.csv";
my $newpath = "Z:/Network/HOM/missing_NL/Missing_Neighbor_030716-031316.csv";


my $meh = $login->put($path, $newpath);

Answer

The login method doesn't return an object. put is a method of the main Net::FTP object, call it on the $s object instead:

$s->put($path, $newpath);
Comments