Wuzzup everyone.
I'm new to perl but learning extremely fast. I'm trying to create a script that will telnet or ftp into a UNIX box and go to a dir and for specific files specific files before proceeding. I want to add this piece into my main script. If the files exist then continue with the rest of the script. If the files don't exist then abort script and display an error to the end user.
This script below will ftp to UNIX and display the .txt files in that dir to the enduser.
#!/usr/bin/perl
use Net::FTP;
my $robin="testenvironment";
my $buck="/mpe/msne/rfwo";
$ftp=Net::FTP->new($robin,Timeout=>240) or $newerr=1;
push @ERRORS, "Can't ftp to $host: $!\n" if $newerr;
myerr() if $newerr;
print "Connected\n";
$ftp->login("username","password") or $newerr=1;
push @ERRORS, "Can't login to $robint: $!\n" if $newerr;
myerr() if $newerr;
$ftp->cwd($buck) or $newerr=1;
push @ERRORS, "Can't cd $!\n" if $newerr;
myerr() if $newerr;
@files=$ftp->dir($buck."/*txt") or $newerr=1;
push @ERRORS, "Can't get file list $!\n" if $newerr;
myerr() if $newerr;
print "Check for 1 2 3 txt Files\n";
foreach(@files) {
print "$_\n";
}
sub myerr {
print "Error: \n";
print @ERRORS;
}
print "Press the ENTER key to exit ...";
$pause = <STDIN>;
Thanks for your assistance.
I'm new to perl but learning extremely fast. I'm trying to create a script that will telnet or ftp into a UNIX box and go to a dir and for specific files specific files before proceeding. I want to add this piece into my main script. If the files exist then continue with the rest of the script. If the files don't exist then abort script and display an error to the end user.
This script below will ftp to UNIX and display the .txt files in that dir to the enduser.
#!/usr/bin/perl
use Net::FTP;
my $robin="testenvironment";
my $buck="/mpe/msne/rfwo";
$ftp=Net::FTP->new($robin,Timeout=>240) or $newerr=1;
push @ERRORS, "Can't ftp to $host: $!\n" if $newerr;
myerr() if $newerr;
print "Connected\n";
$ftp->login("username","password") or $newerr=1;
push @ERRORS, "Can't login to $robint: $!\n" if $newerr;
myerr() if $newerr;
$ftp->cwd($buck) or $newerr=1;
push @ERRORS, "Can't cd $!\n" if $newerr;
myerr() if $newerr;
@files=$ftp->dir($buck."/*txt") or $newerr=1;
push @ERRORS, "Can't get file list $!\n" if $newerr;
myerr() if $newerr;
print "Check for 1 2 3 txt Files\n";
foreach(@files) {
print "$_\n";
}
sub myerr {
print "Error: \n";
print @ERRORS;
}
print "Press the ENTER key to exit ...";
$pause = <STDIN>;
Thanks for your assistance.