Michael Doran Home Page
Contact | Site Map | Search  
  Home > Archives > Using Scripts > oclc-xfer.pl
Using Scripts to Automate Voyager Tasks

oclc-xfer.pl

#!/usr/local/bin/perl -w

########################################################
#
#  Perl script: oclc-xfer.pl 
#
#  1999, Michael Doran, doran@uta.edu
#  University of Texas at Arlington Libraries
#
#  FTP's Pbulkexport output file to OCLC server.
#
#  See: bullwinkle:/usr/local/scripts/oclc-export
#
#  (OCLC User & Network Support 1-800-848-5800)
#
########################################################

use Net::FTP;  # part of libnet collection of Perl modules

# Variables
 $ftp_site = "edx.oclc.org";
 $local_dir = "/opt/incoming/oclc";
 $oclc_file = "EDX.EBSB.IUA.FTP";
 # plus sign escaped out in remote file name
 $remo_file = "'EDX.EBSB.IUA.FTP(\+1)'";
 $done_file = "EDX.EBSB.IUA.FTP.done";
 $user_file = "/usr/local/scripts/oclc-user.txt";
 $pswd_file = "/usr/local/scripts/oclc-pswd.txt";

# Change to the oclc file directory
chdir($local_dir) or die "Cannot cd to $local_dir.\n";

# Read in user name and assign contents to variable
open(USRNM, "< $user_file")
	or die "Cannot open $user_file for reading: $!";
chomp($username = );  # chomp newline character 
close(USRNM);

# Read in old password and assign contents to variable
open(PSWDFILE, "< $pswd_file")
	or die "Cannot open $pswd_file for reading: $!";
chomp($old_pw = );  # chomp newline character 

# Create a new random password
@pw_chars = ("A".."Z","a".."z",0..9);
$new_pw = join("", @pw_chars[ map {rand @pw_chars } (1..8) ]);

# This construct changes the password every session
$password = "$old_pw/$new_pw/$new_pw";

# Open password file for writing
open(PSWDFILE, "> $pswd_file")
	or die "Cannot open $pswd_file for writing: $!";

# Start FTP: connect and login
$ftp = Net::FTP->new($ftp_site)
		or die "FTP: Couldn't connect: $@.";
$ftp->login($username, $password)
		or die "FTP: Couldn't login.";

# Save new password before doing anything else
print PSWDFILE "$new_pw\n";
close(PSWDFILE);

# Specify a binary tranfer
$ftp->binary()
		or die "FTP: Couldn't specify binary type.";

# Transfer bulk export file
$ftp->put($oclc_file, $remo_file)
		or die "FTP: Couldn't put $oclc_file.";

# Exit from the ftp session
$ftp->quit()
		or die "FTP: Couldn't quit.";

# Rename OCLC file
rename("$oclc_file", "$done_file")
		or die "Couldn't rename $done_file.";

exit(0);