I am a new subscriber to the list, so please forgive me if this is a FAQ or
has been recently asked.

I have a situation where I'm performing an FTP to transfer some files to a
less-than-reliable site.  I have my FTP code inside an eval block so that
the program can die and send a message to a pager if the FTP fails (code
snippet shown below message). This works just fine, except that I am getting
a lot of unnecessary messages to the pager because the site will sometimes
not accept a connection, but then a few minutes later will be OK.  So,
instead of doing a die to send a page on the first attempt, I'd like to set
it up so that the connection would be attempted a total of 3 times before
failing and sending a page, pausing a few minutes (say 5 minutes) between
attempts.  I can't quite wrap my mind around how to accomplish that though.
I know I can use the sleep function to do the pause, but how should I
restructure the eval block(s)?

eval{
 
  # Connect to the remote FTP site

  $ftp = Net::FTP->new('firewall', Debug => 1) 
    or die "can't connect to firewall\n";

  $ftp->login('user' . '@' . 'my.ftp.site','passwd','acct');
    
  $ftp->cwd('/mylib') 
     or die "can't change to remote directory\n";

  $ftp->binary;

  # Loop through all files in the local directory, transferring each
  # file to the remote FTP server

  foreach $file (@files)
  {
    
    if (length($file)>2 and $file ne 'irp_arc') 
    {      
      $ftp->put($file) or die "failed to transfer file $file\n";
    }  
  }

  $ftp->quit();
  
};

# If there were any errors, send a page and do not move or delete
# the source files before exiting

if($@)
{
  $errmsg = $@;
  $smtp = Net::SMTP->new('my.smtp.server',Timeout =>60);
  $smtp->mail($ENV{USER});
  $smtp->to($beeper);
  $smtp->data();
  $smtp->datasend("To: Tax Pager\n");
  $smtp->datasend("From: Honts809 IRP FTP\n");
  $smtp->datasend("Subject: IRP FTP error: $errmsg\n");
  $smtp->datasend("\n");
  $smtp->dataend;
  $smtp->quit;
  
  exit;      
        
}

Thanks for any and all suggestions!

Sterling Price










**********************************************************************
Notice:  The area code for the Wal-Mart Bentonville General 
Office in the US has changed from 501 to 479.  Please make
sure that you are dialing 479 when making calls to any 
General Office location.

**********************************************************************
This email and any files transmitted with it are confidential
and intended solely for the individual or entity to 
whom they are addressed.  If you have received this email
in error destroy it immediately.
**********************************************************************


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to