#!/usr/local/bin/perl -w
########################################################
#
# Perl script: marciver.pl
#
# 1999, Michael Doran, doran@uta.edu
# University of Texas at Arlington Libraries
#
# Retrieves files from the marcive ftp server
# for bulk import into the Voyager database.
#
########################################################
use Net::FTP; # part of libnet collection of Perl modules
# Variables
$ftp_site = "ftp.marcive.com";
$username = "anonymous";
$password = "Your_Name\@Your_Domain.edu";
$remote_dir = "/Path_to_Directory";
$local_dir = "/opt/incoming/marcive";
# Arrays
@ftp_files = ("UTA*", "RELATED*");
# Change to the incoming marcive directory
chdir($local_dir) or die "Cannot cd to $local_dir.\n";
# Delete two-week old files
chdir("$local_dir/store") or die "Cannot cd to $local_dir/store.\n";
foreach $file_match (@ftp_files) {
foreach $old_file (glob $file_match) {
unlink($old_file)
or warn "Trouble deleting store/$old_file: $!";
}
}
# Move last weeks files to storage, i.e. "store" directory
chdir($local_dir) or die "Cannot cd to $local_dir.\n";
foreach $file_match (@ftp_files) {
foreach $old_file (glob $file_match) {
rename("$old_file", "store/$old_file")
or warn "Trouble moving $old_file: $!";
}
}
# Start FTP: connect, login, and cd to UTA's directory
$ftp = Net::FTP->new($ftp_site)
or die "FTP: Couldn't connect: $@.";
$ftp->login($username, $password)
or die "FTP: Couldn't login.";
$ftp->cwd($remote_dir)
or die "FTP: Couldn't change directory.";
$ftp->binary()
or die "FTP: Couldn't specify binary type.";
# Put list of files into an array
@list_files = $ftp->ls()
or die "FTP: Couldn't get list of files.";
# Retrieve bulk import files
foreach $file_match (@ftp_files) {
foreach $file (@list_files) {
if ($file =~ /^$file_match/) {
$ftp->get($file)
or die "FTP: Couldn't retrieve $file.";
}
}
}
# Exit from the ftp session
$ftp->quit()
or die "FTP: Couldn't quit.";
exit(0);
|