Perl has a library that allows that.  I've used it for years, and it's
very reliable except for one problem... the password feature is unencrypted.
You would need to use the require "ftp.pl"; directive in your program to 
use the library, though.  I'll send you a short sample with this, but it's
up to you to fix it more than this.

Bill Ward

Short Sample:

#! /usr/bin/perl
require "ctime.pl";
require "ftp.pl";
require "flush.pl";
use File::Path;

# Prototype Perl FTP example by William Ward, 1/26/2000

$ENVP'PATH'}='/bin:/usr/bin';
$ENV{'SHELL'}='/bin/csh';

$my_name=$0;
$my_pid=$$;
$ftpHost="ftp.redhat.com";
$USER_NAME="anonymous";
$USER_PASSWD="[EMAIL PROTECTED]";
$file="myfile";
$local_file_name="thisfile";
$time_to_live=72;
$retry_interval=3600;

$message=sprintf("%s ----- START: $my_name (PID=$my_pid)
-----\n",&timestamp(time,2));
&printflush(STDOUT,$message); 
printf "FTP host: $ftpHost\n";
printf "Account Name to use: $USER_NAME\n";
printf "Account Password: $USER_PASSWD\n";
flush(STDOUT);
connect;
exit;

sub error {
  my($error_number, $error_message) = @_;

  my($message) = sprintf("%s ##### ERROR: $error_message.\n",
    &timestamp(time, 2));  
  &printflush(STDERR, $message);
  &done($error_number);
}

sub connect {
    $x=0;
    if (&ftp::open($ftpHost,21,0,1) !=1) {
        printf "Could not connect to $ftpHost, trying again later\n";
        while (($x<=$time_to_live) && (&ftp::open($ftpHost,21,0,1)!=1))
        {
            printf "Unable to connect to $ftpHost, sleeping $retry_interval
seconds\n";
            flush(STDOUT);
            sleep $retry_interval;
            $x=$x+1;
            printf "Been trying to connect to $ftpHost for %s hours (max %s
days)\n",($x*$retry_interval/3600),($time_to_live*$retry_interval/86400);
        }
        if ($x>$time_to_live)
        {
            printf "Can't open $ftpHost at all, giving up\n";
            printf "Exiting with Error Code 10\n";
            flush(STDOUT);
            &error(10,"Giving up on connection");
        }
        printf "Finally got a connection to $ftpHost\n";
    }
    printflush (STDOUT, "Connected to $ftpHost\n");
    ##### Log in #####
    if (&ftp::login($USER_NAME,$USER_PASSWD)!=1) {
        printf "Can't login to $ftpHost\n";
        printf "Exiting with Error Code 20\n";
        flush(STDOUT);
        &error(20,"Exiting due to incorrect Password");
    }
    printflush (STDOUT, "Logged in as $USER_NAME\n");
    ##### Set Mode to Binary #####
    if (&ftp::type("I") !=1) {
        printf "Can't change mode to binary\n";
        printf "Exiting with Error Code 30\n";
        flush(STDOUT);
        &error(30,"Exiting due to problem changing mode to Binary");
    }
    printflush (STDOUT,"Changing mode to Binary\n");
    if (&ftp::get($file,$local_file_name)!=1) {
            printf "Can't get $file\n";
            printf "Exiting with error code 100\n";
            flush(STDOUT);
            &error (100,"Exiting due to inexistant file");;
        }
        &ftp::close;
}


-----Original Message-----
From: Jim Baxter [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 26, 2000 10:53 AM
To: Redhat
Cc: recipient.list.not.shown; @nswcphdn.navy.mil
Subject: FTP that will script please


Hi

We do not seem to be able to run ftp from a shell script or script ftp.
The man page talks about macros but they go away at close.
What we need is the ability to start ftp, login and get (or put) a list of
files and
log off all from a shell script

Can some one tell me how to do it or where to get RPM of another version of
ftp that
will do it?

Thanks


Jim Baxter
MIS
Morrison Supply Company


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to