#!/usr/bin/perl use Net::FTP; # Remote host variables passed by the caller # Calling sequence: checkshopatronfiles.pl arg1 arg2 arg3 arg4 arg5 chomp($rhost=@ARGV[0]); # Remote host domain, alias or IP address chomp($ruserid=@ARGV[1]); # Remote userid chomp($rpasswd=@ARGV[2]); # Remote password chomp($rdirectory=@ARGV[3]); # Remote directory chomp($rfilename=@ARGV[4]); # Remote file name # Local variables for LOG file name # $log1=substr ($rfilename, 0, rindex($rfilename, ".")); $log1=$rfilename; # Use name as passed with no extension $log2=".lg"; $lfilename=$log1.$log2; # Log file name # Local variables for OUT file name # $out1=substr ($rfilename, 0, rindex($rfilename, ".")); $out1=$rfilename; # Use name as passed with no extension $out2=".sz"; $ofilename=$out1.$out2; # Output file name open (LOGFILE, '>', $lfilename); # Always create the log file print LOGFILE "Remote host=$rhost\n"; print LOGFILE "Remote userid=$ruserid\n"; print LOGFILE "Remote passwd=$rpasswd\n"; print LOGFILE "Remote directory=$rdirectory\n"; print LOGFILE "Remote filename=$rfilename\n"; open (OUTFILE, '>', $ofilename); # Always create the output file $ftp=Net::FTP->new($rhost,Timeout=>10) or $errcd=1; push @ERRORS, "Can't connect to $rhost\n" if $errcd; myerr() if $errcd; print LOGFILE "Connected\n"; $ftp->login($ruserid,$rpasswd) or $errcd=2; push @ERRORS, "Can't login to $rhost\n" if $errcd; myerr() if $errcd; print LOGFILE "Logged in\n"; $ftp->cwd($rdirectory) or $errcd=3; push @ERRORS, "Can't cd to $rdirectory\n" if $errcd; myerr() if $errcd; print LOGFILE "Found directory\n"; $ftp->binary; $rfilesize=$ftp->size($rfilename) or $errcd=4; push @ERRORS, "Can't get file size for file $rfilename\n" if $errcd; myerr() if $errcd; print OUTFILE "$rfilesize\n"; print LOGFILE "Got file size\n"; print LOGFILE "Remote filesize=$rfilesize\n"; print LOGFILE "Exit code=0\n"; close (LOGFILE); close (OUTFILE); $ftp->quit; exit $errcd; sub myerr { print LOGFILE "Error=$errcd\n"; print LOGFILE @ERRORS; close (LOGFILE); print OUTFILE "0\n"; close (OUTFILE); exit $errcd; }