lu5026.pl
Cathy Sicard (cathy@lsu.edu)
12/21/2006
This program will FTP invoice files from YBP to Xfer, add an extension to the files in Xfer and rename the files on YBP's server.
INPUT: Invoice file from YBP OUTPUT: YBP invoice files will be put into site's Xfer directory. SORT OPTIONS: None
Acquisitions
Production
######## BEGIN SIRSI HEADER CODE ######### BEGIN { chomp($script = `getpathname rptscript`); $runsubdir = ``$script/Runsubs''; unshift(@INC,$runsubdir); } use setup_cust_vars; use new_initial; use finalize_var; use file_manipulate;
setup_variables(\%Directives, \%TempFiles); Initialize(\%Directives, \%TempFiles); BuildOptions(\%Directives, \%TempFiles); require(``report_header.pl'');
######## END SIRSI HEADER CODE ########
####### BEGIN SET UP MODULES ######## use Net::FTP; ####### END SET UP MODULES #########
####### The file on the YBP ftp server will be in the format: 36001206.edi. ##### ####### FTP all *.edi files to /home/sirsi/*/Unicorn/Xfer & change the file extensions to x12. ##### ####### Rename all files on YBP's FTP server after they have been FTP'd to /home/sirsi/*/Unicorn/Xfer. #####
####### SET UP HOSTNAME, LOGIN ID AND PASSWORD ####
my $remotehost = ``ftp.ybp.com''; my $remotedir = ``invoice''; my $user = ``lsu3600''; my $pass = ``yaK5w7'';
#### $@ contains the return status of NET::FTP #### $? contains the return status of $ftp commands ex. $ftp->login, $ftp->cwd, etc. #### $ftp->message contains any messages returned from remote FTP server.
PrintMessage(``Connecting to YBP \n'',``$TempFiles{'a'}''); if ($ftp = Net::FTP -> new ( ``$remotehost'', Debug => 0)) { PrintMessage(``Connection made to $remotehost \n'', ``$TempFiles{'a'}''); $ftp_prob=0; } else { PrintMessage(``Error: Connection to the FTP server $remotehost failed \n Reason: $@ \n'', ``$TempFiles{'a'}''); $ftp_prob=1; }
if (!$ftp_prob) {
PrintMessage(``Logging onto $remotehost \n'',``$TempFiles{'a'}'');
if($ftp->login($user,$pass)) {
PrintMessage(``Logon to $remotehost successful \n'',``$TempFiles{'a'}'');
$ftp_prob=0;
}
else {
$errormsg = $ftp->message;
PrintMessage(``Error: Logon to $remotehost failed \n Reason: $errormsg \n'', ``$TempFiles{'a'}'');
$ftp_prob=1;
}
}
if (!$ftp_prob) {
PrintMessage(``Changing to YBP $remotedir directory \n'',``$TempFiles{'a'}'');
if ($ftp->cwd(``$remotedir'')) {
PrintMessage(``Change to YBP $remotedir directory successful \n'',``$TempFiles{'a'}'');
$ftp_prob=0;
}
else {
$errormsg = $ftp->message;
PrintMessage(``Error: Change to YBP $remotedir directory failed \n Reason: $errormsg \n'', ``$TempFiles{'a'}'');
$ftp_prob=1;
}
}
if (!$ftp_prob) { PrintMessage(``Listing files in YBP $remotedir directory \n'',``$TempFiles{'a'}''); if (@filenames = $ftp->ls) { PrintMessage(``Listing files in YBP $remotedir directory successful \n'',``$TempFiles{'a'}''); $ftp_prob=0; } else { $errormsg = $ftp->message; PrintMessage(``Error: Listing files in YBP $remotedir directory failed \n Reason: $errormsg \n'',``$TempFiles{'a'}''); $ftp_prob=1; } }
if (!$ftp_prob) {
$filenum = 0;
foreach (@filenames) {
if (/^[0-9]{8}\.edi$/) {
PrintMessage(``Transferring file(s) from YBP $remotedir directory to /home/sirsi/LALU/Unicorn/Xfer \n'',``$TempFiles{'a'}'');
$target_path=``/home/sirsi/LALU/Unicorn/Xfer/'' . $filenames[$filenum] . ``.x12'';
$new_file_name=``$filenames[$filenum]'' . ``.DONE'';
if ($ftp->get($filenames[$filenum], $target_path)) {
PrintMessage(``FTP GET command successful on file $filenames[$filenum]\n'',``$TempFiles{'a'}'');
$ftp_prob=0;
PrintMessage(``Renaming file $filenames[$filenum] on YBP server to $filenames[$filenum].DONE \n'',``$TempFiles{'a'}'');
if ($ftp->rename($filenames[$filenum], $new_file_name)) {
PrintMessage(``FTP RENAME command successful on file $filenames[$filenum] \n'',``$TempFiles{'a'}'');
}
else {
$errormsg = $ftp->message;
PrintMessage(``Error: FTP RENAME command failed on file $filenames[$filenum] \n Reason: $errormsg \n'',``$TempFiles{'a'}'');
$ftp_prob=1;
}
}
else {
$errormsg = $ftp->message;
PrintMessage(``Error: FTP GET command failed on file $filenames[$filenum]\n Reason: $errormsg \n'',``$TempFiles{'a'}'');
$ftp_prob=1;
}
}
####### add code to rename files on YBP server after download
$filenum++;
}
}
$ftp->quit;
if (!$ftp_prob) { PrintMessage(``FTP process completed successfully \n'',``$TempFiles{'a'}''); }
####### END SET UP HOSTNAME, LOGIN ID AND PASSWORD ######
$Directives{'status'} = $?; require(``folddata.pl''); finalize(\%Directives, \%TempFiles);