I think I understand how to use Net::FTP. I am calling a Perl script from a Unix script. If the Perl script cannont connect to the server, I think it sends back a return code to the Unix script. Does anyone know how to capture the return code in the Unix script?
You should try printing out the result of $? as soon as the Perl script ends just to see what it is doing. Perhaps you may have to get creative and instead of saying:
$ftp = Net::FTP->new($ftp_server, Debug => 0) or die "Cannot Connect to FTP Server";
you can say:
$ftp = Net::FTP->new($ftp_server, Debug => 0) or exit 255;
As you have seen in some of the previous posts, $@ is where the Net::FTP exit status is placed. This is the syntax I use:
my $ftp = Net::FTP->new
(
"someserver.com",
Timeout => 60
) or die "Could not connect to someserver: $@\n";
$ftp->login($username, $password) or die "Could not log in. $ftp->message\n";
Another thing you could do is set Debug to a none 0/undef:
$ftp = Net::FTP->new($ftp_server, Debug => 1) or die "Cannot connect: $@\n"; # This will generate more info for you.
Remember that some of your errors are going to STDOUT unless you redirect them in your program or the shell script executing it. If you need to exit immidiately use die if not use warn, the exit command will only yield a number you will have to give meaning to.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.