- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help with perl NET::ftp script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2014 09:23 AM
05-28-2014 09:23 AM
Help with perl NET::ftp script
Good morning, I need help with enabling error tracking or messaging execution success within the script.
The perl script (I attached the section that I need make some changes) runs a for loop and opens a ftp connection to group of servers to either send or get files on each ftp server. if a connection to a server fails it continues to the next server.
The script does a $FtpObject = Net::FTP->new($ServerHost{$Host}); then $Ret=$FtpObject->login($User,$How); The problem I have is that sometimes I get a message indicating that the login methond cannot be called with an undefined value and I dont know where is this originating but I suspect it is failing because of the FtpObject is not complete.
Error : Can't call method "login" on an undefined value at line 507
I would like to add: or die "[Error] UNABLE TO CREATE FTP OBJECT: [$@]";
with in the FtpOpen line to get information as to which ftp server is failng to open and send e-mails to alert us.
can someone suggest the bets way to modify this part of the script.
Please let me know if my explanation needs more details or to be better explained.
thank you
###########################################################################
# Process for each host in our Hash array
###########################################################################
foreach $Host (keys(%ServerHost))
{
if ( "$ServerHost{$Host}" eq "localhost" )
{
$UseFtp=0;
}
else # Must be remote ( Using FTP )
{
$UseFtp=1;
#Force passive FTP
#if ( "$ServerHost{$Host}" eq "server.net" )
if ( "$ServerHost{$Host}" eq "ftp.server.com" )
{
$FtpObject = Net::FTP->new($ServerHost{$Host}, Passive => 1, Debug => 1);
}
else
{
$FtpObject = Net::FTP->new($ServerHost{$Host});
}
($User,$How)=split('/',$ServerUser{$Host});
$Ret=$FtpObject->login($User,$How); ## <<----- Line 507
if (! $Ret)
{
$LogFails{$Host}++;
if ( $LogFails{$Host} <= 3 )
{
MailIt("$WhoFindsOut",
"Cash file import failed to login to Server: $Host",
"There was a problem attempting to login to the server: ".
"$Host");
} elsif ( $LogFails{$Host} =~ /0\Z/ ) # Counts that end w/ zero
{
MailIt("$WhoFindsOut",
"Cash file import failed to login to Server: $Host",
"There is a reoccurring problem attempting to login to ".
"the server: $Host. Login has failed $LogFails{$Host} ".
"times.");
}
next;
}else
{
if ( $LogFails{$Host} )
{
MailIt("$WhoFindsOut",
"Cash file import message: Server, $Host, back online.",
"Sucessfully logged into server: $Host, after ".
$LogFails{$Host}.
" failed login attempt(s).");
}
$LogFails{$Host}=0;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2020 07:18 PM
06-22-2020 07:18 PM
Re: Help with perl NET::ftp script
@Juan M Leon wrote:$FtpObject = Net::FTP->new($ServerHost{$Host}, Passive => 1, Debug => 1);
}
else
{
$FtpObject = Net::FTP->new($ServerHost{$Host});
The problem is due to the fact that you never check for the success / failure of the call to Net::FTP::new above.
The following check should achieve what you intend and avoid the error you are seeing intermittently:
die "[Error] UNABLE TO CREATE FTP OBJECT: [$@]" if not defined $FtpObject;