Hello All,

Want two more help..
i am trying to send email to me whenever there is some problem is my script:
here is my script:
#!/bin/perl -w
#
#use strict;
use Net::FTP;
my
($hostname,@fArr,$h_ftp,$file,$onlyFile,$onlyExt,$newfile,$tstamp,$dot,$hyph
en);
$hostname = 'ENTFTP.CONAGRA.CAG'; 
open(STDERR, ">stderr.txt");
open(STDOUT, ">stdout.txt");
open(EMAIL, "|mail [EMAIL PROTECTED]");
#Get the parameters passed from CA-Unicenter
$file = $ARGV[1];
print "file name is $file\n";
#logging into ENTFTP server
        $! = ' ';
        
        $h_ftp = Net::FTP->new($hostname, Debug => 0) || print EMAIL "Cannot
connect to $hostname : $!";
        (if $! ne ' ' )
               {die "Cannot connect to $hostname : $!";}
        $! = ' ';                       
        $h_ftp->login( 'nucibamr','nuc0108') || print EMAIL "Cannot log on
to $hostname : $!" ;
        (if $! ne ' ' )
               {die "Cannot log on to $hostname : $!";}
               
#new name of the file
                $tstamp = time;
                @fArr = split(/\./, $file);
                $onlyFile = $fArr[0];
                $onlyExt = $fArr[1];
                $dot = '.';
                $hyphen = '-';
                
                $newfile = $onlyFile.$hyphen.$tstamp.$dot.$onlyExt;
                print "newfile name is $newfile\n";
                
                $! = ' ';
                $h_ftp->get($file,$newfile) || print EMAIL "Cannot get file
$file from $hostname : $!";
                (if $! ne ' ' )
                        {die "\nCannot get file $file from $hostname : $!";}
                        
                print "$file downloaded from $hostname as $newfile\n";
                print "***********************************************\n";
                        
       $h_ftp->quit || warn "Cannot quit - check connection : $!";;

The mail programs seems to be not working - I am getting error as:
The name specified is not recognized as an
internal or external command, operable program or batch file.

1) Please let me know how to send the email
2) Also if you notice that each time I run my script the stderr.txt and
stdout.txt is overwritten. Please let me know how to append the file each
time instead of overwriting it.

Thanks,
Rajib


-----Original Message-----
From: Wening Andreas [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 30, 2002 12:41 AM
To: Sengupta, Rajib (CC-Contractor)
Cc: '[EMAIL PROTECTED]'
Subject: RE: Want help for FTP using Perl


Ok, 

here some changes to "make it nice".  I didn't let it run, but you should be
able to resolve the typos.

use strict;
use Net::FTP;

# variables
my $ftp_server = "whatever.com";
my $ftp_account = "somename";
my $ftp_pwd = "password";
my $searchstr = "\.zip";
my (@allfiles,$h_ftp,$n, $file, $file_name, $file_ext, $selectedfiles);
my ($newfile,$tstamp);

#logging into ftp server
$h_ftp = Net::FTP->new($ftp_server, Debug => 0);
$h_ftp->login($ftp_account, $ftp_pwd) or die "Couldn't login to
$ftp_server\n";

# check if there are files in the directory
@allfiles = $h_ftp->ls();
$n = @allfiles;
if ($n == 0) {
        print "No files for download on $ftp_server\n";
        exit 0;
        }
print "total number of files to download $n \n";        
        
# select files which meet the searchstring
foreach $file (@allfiles) {
        if ($file =~ /$searchstr/){push(@selectedfiles, $file)};
        }
$n = @selectedfiles;
if ($n == 0) {
        print "No zip files for download on $ftp_server\n";
        exit 0;
        }
                
#download selected files
foreach $file (@selectedfiles) {
        $tstamp = time;
        $newfile = $file_name."-".$tstamp.".".$file_ext; #maybe it's
...amp."\.".$fil...
        print "newfile name is $newfile\n";
        $h_ftp->get($file,$newfile) or die "Can't download file $file\n";
        print "$file downloaded from $ftp_server\n";
        }
$h_ftp->quit or die "Couldn't quit\n";

#insert here the email part and just send in the content the @selected files

exit 0;

A simple method to write everything in a log file:
myscript.pl >> c:\logfiles\myscriptlog.txt (put this in the scheduler)

If you really want to get after each download an email look at Net:SMTP.
 
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to