Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2477
  • Last Modified:

Can't call method "login" on an undefined value at ftp.pl line 49.

I have a perl script that runs on my linux servers, but it fails on 2 of them with the following error:

Can't call method "login" on an undefined value at ftp.pl line 49.

 I believe the all the server are all the perl version and modules.

$ftp = Net::FTP->new("$ht", Debug => 1)  or &fail;
     49 $ftp->login("sitsend",decrypted) or &fail;  
     50 $msg = "Connection msg: ".$ftp->message."";
     51 print "Connected new  ".$ftp->message."\n";  ### for testing
     52 $ftp->quit;

Open in new window

0
MatthewF
Asked:
MatthewF
  • 3
  • 3
1 Solution
 
Adam314Commented:
If the Net::FTP module can't connect, it'll return undef.  So on line 1, it tries to connect.  If it can't, it calls your fail subroutine.  Does this subroutine exit, or does it return?  If it returns, your program will then try to login on line 2/49.  This will give you the error you are seeing.
0
 
MatthewFAuthor Commented:
So &fail does not run.  This is &fail

if ($msg !~ /Virtual user test logged in/ && not -e "$location/$ht.ftpflag") {
open MAIL,"|/usr/bin/mailx -s $sub $TO";
print MAIL $down_msg;
close MAIL;
`echo "Unable to ftp into $ht at $mon/$mday $hour:$min" >> $log`;
`echo "$ht" > $location/$ht.ftpflag`;
exit;
 }
}






0
 
Adam314Commented:
In fail, from where does $msg come?  What are $location and $ht?  Unless the conditions on the first line you posted are met, the exit statement will not be executed, and the fail subroutine will return, allowing the line 2/49 in your original post to execute.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MatthewFAuthor Commented:
$ht=`hostname`;
chomp $ht;
$location="/opt/bin/agents/monitor";
$down_msg="Unable to ftp into $ht" ;


Additionally, I ftped the script from a server that is working
0
 
Adam314Commented:
try this change
sub fail {
    ...
    if ($msg !~ /Virtual user test logged in/ && not -e "$location/$ht.ftpflag") {
        open MAIL,"|/usr/bin/mailx -s $sub $TO";
        print MAIL $down_msg;
        close MAIL;
        `echo "Unable to ftp into $ht at $mon/$mday $hour:$min" >> $log`;
        `echo "$ht" > $location/$ht.ftpflag`;
        exit;
    }
    else {                                #NEW
        die "sub fail: did not exit\n";   #NEW
    }                                     #NEW
}

Open in new window

0
 
MatthewFAuthor Commented:
Adam,
 it turned out ftp was down .. lol... tks for the help
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now