Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > FTP error checking- call e-mail sub

Reply
Thread Tools

FTP error checking- call e-mail sub

 
 
Nex_s
Guest
Posts: n/a
 
      08-04-2005
Hi All,

I'm doing my best to get through this one. I want to error check on
each part of the FTP process. If it fails I want to call an e-mail
sub. Unfortunately the FTP process prints an error and as such my
script fails. For some reason I also can't pass the appropriate error
message to the e-mail sub neither. Here's my code.

$errmessage = "file does not exist";
$ftp->put("temp_buffer1.txt")
or die &email($errmessage);

sub email ($errmessage) {

use Mail::Sendmail;
my %mail;
$mail{From} = 'From Me <(E-Mail Removed)>';
$mail{To} = 'To Me <(E-Mail Removed)>';
$server = '123.456.789.10';

$mail{Smtp} = $server;
$mail{Subject} = 'Process failure!!';
$mail{Message} = $errmessage;
$mail{Message} = "It was sent on " . Mail::Sendmail::time_to_date() .
"\n";

# Go send it
sendmail %mail

}

Any help would be appreciated.

Chris

 
Reply With Quote
 
 
 
 
Dave Weaver
Guest
Posts: n/a
 
      08-08-2005
On 4 Aug 2005 11:09:50 -0700, Nex_s <(E-Mail Removed)> wrote:
>
> $errmessage = "file does not exist";
> $ftp->put("temp_buffer1.txt")
> or die &email($errmessage);


Why do you think the only possible failure is the lack of existence of
the file you want to put? You might as well use the proper failure
message that Net::FTP has. This is rougly how I'd do it (untested) :

$ftp->put( $filename )
or fatal( "Couldn't put '$filename' : " . $ftp->message )

sub fatal {
my ( $msg ) = @_;
email( $msg );
exit 1; # use "die $msg" instead, if you want the msg to STDERR too.
}


> sub email ($errmessage) {


This has been addressed in another reply.

> use Mail::Sendmail;
> my %mail;
> $mail{From} = 'From Me <(E-Mail Removed)>';
> $mail{To} = 'To Me <(E-Mail Removed)>';
> $server = '123.456.789.10';
>
> $mail{Smtp} = $server;
> $mail{Subject} = 'Process failure!!';
> $mail{Message} = $errmessage;
> $mail{Message} = "It was sent on " . Mail::Sendmail::time_to_date() .
> "\n";


Written slightly nicer (IMHO) like this:

sub email {
my ( $errormsg ) = @_;

use Mail::Sendmail;
my %mail = (
From => 'From Me <(E-Mail Removed)>',
To => 'To Me <(E-Mail Removed)>',
Smtp => '123.456.789.10',
Subject => 'Process failure!!',
Message => $errormsg
. "\nIt was sent on "
. Mail::Sendmail::time_to_date()
."\n",
);

sendmail %mail or die $Mail::Sendmail::error
}

(untested)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Death To Sub-Sub-Sub-Directories! Lawrence D'Oliveiro Java 92 05-20-2011 06:50 AM
Recognising Sub-Items and sub-sub items using xslt Ben XML 2 09-19-2007 09:35 AM
sun.net.ftp.FtpProtocolException: Error reading FTP pending reply long990802@gmail.com Java 3 12-11-2005 02:46 AM
FTP error checking- call e-mail sub Nex_s Perl Misc 0 08-04-2005 06:07 PM
Net::FTP problems getting files from Windows FTP server, but not Linux FTP Server. D. Buck Perl Misc 2 06-29-2004 02:05 PM



Advertisments