On Wed, Apr 9, 2008 at 1:56 PM, Wagner, David --- Senior Programmer
Analyst --- WGO <[EMAIL PROTECTED]> wrote:
>         I have a hash which contains for each entry the email which I
>  need to ftp to a particular location with a specified name. I could
>  write out the file and then do the ftp. But since I have the necessary
>  data in an audittrail report, I was wondering if I can ftp from a
>  variable using ftp commands?
>
>         I took a look at the doc on Net::FTP, but nothing stood out and
>  did not find an example.
snip

I don't fully understand what you desire to do.  It sounds like you
wish to FTP to a machine using a user and password retrieve by the
Perl program (that fact that is stored in a hash is irrelevant) and
maintain a log of the fact that you are making this FTP connection.
This is simple in Perl:

#warning untested code as I don't maintain and FTP servers anymore
(they are insecure, use scp or sftp instead)
#!/usr/bin/perl

use strict;
use warnings;
use Net::FTP;
use POSIX;

sub log {
   my $log = shift;
   print $log map { strftime "%Y-%m-%d %H:%M:%S $_\n", localtime() } @_;
}

my $host = "localhost";
my $user = "foo";
my $pass = "bar";

open my $log, ">>", "path/to/audit.log"
   or die "could not open audit log: $!";

$SIG{__DIE__} = sub { log($log, shift) };

my $ftp = Net::FTP->new($host)
      or die "Cannot connect to $host: $@";

log($log, "connected to $host");

$ftp->login($user, $pass)
      or die "Cannot login as $user: ", $ftp->message;

log($log, "logged in as $user");

#do ftp stuff you need to do, logging as you go

$ftp->quit;

log($log, "logged out as $user on $host");

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to