#!/usr/bin/perl
# MacPerl script for moving pdf files to 
# my web directory for serving by my database.
# Modufy the code to your liking, save as a droplet.
# Then when you drop files into it they automatically
# get ftp'd.   Chris Seidel July 2000
# Should be modified to check for a systematic file name
# and prompt you for a proper one if not found.

use Net::FTP;

print "Connecting to ftp server... \n";
my($user,$password, $ftp, $ftphost,$rem_dir,$base, @list);

#set rem_dir (remote directory) to wherever you want to serve the files from
$rem_dir = "/home/seidel/public_html/Argus/Lib";
$user = "your_username";
$password = "your_password";
$ftphost = "your.server.edu";

$ftp = Net::FTP->new( $ftphost );

if ( $user ne "" )
{
    $ftp->login( $user, $password )
	|| die "$0: login failed: \"", $ftp->message, "\"\n";
}
else
{
    $ftp->login()
	|| die "$0: login failed: \"", $ftp->message, "\"\n";
}
#print " $ftp->message\n";
print "Changing Directory to $rem_dir\n";

$ftp->cwd( $rem_dir )
    || die "$0: $rem_dir: unable to change directory: \"", $ftp->message, "\"\n"
	if $rem_dir ne "";

( $base = $ftp->pwd() )
    || die "$0: can't find current directory: \"", $ftp->message, "\"\n";

$result = $ftp->binary();

print "Result: $result\n";
foreach $file (@ARGV){
# ---------------------------------------------------------------------------
print "Placing file in remote directory... \n";

$ftp->put( $file )
		|| die "$0: $file: put failed: \"", $ftp->message, "\"\n";

}
#diagnostics
#@list = $ftp->ls( '-lRa' );
#if ( @list == 0 )
#{
#    die "Please Report!!!: nothing returned by 'ls -lRa'\n",
#	"FTP message: ", $ftp->message, "\n";
#}
#foreach (@list) {
#print "$_\n";
#}

$ftp->quit()
    || warn "$0: quit returned: \"", $ftp->message, "\"\n";
print "Done.\n";
sleep(3); #let me see the window for 3 seconds before quiting
&MacPerl'Quit(2);
