Re: [Ssh-sftp-perl-users] help needed with SFTP
Brought to you by:
dbrobins
From: Howard, C. <Ho...@pr...> - 2009-01-22 18:47:19
|
And here is my sample script, just in case anybody would find it useful. I use a file in this user's home directory to contain the host, username, and password. If you do that make sure the file has pretty tight filesystem permissions. #!/usr/bin/perl # # $ftp_data_file = $ENV{'HOME'}.'/ftpdata'; # For awhile we will keep a log of what is happening open(LOG,">>/tmp/SAMPLE_upload.log"); print LOG "--------------\n"; open(FTP_DATA,$ftp_data_file) || print LOG "unable to open ftp data file $ftp_data_file\n"; while(<FTP_DATA>) { next if ( m/^\s*#/ ); ($key,$value) = split(); $ftp_data{$key} = $value; } # # open an ftp connection using # 'SAMPLE_host', 'SAMPLE_user', 'SAMPLE_password' # from the ftp_data hash # $now_string = localtime(); print LOG "Starting $now_string \n"; if( !defined($ftp_data{'SAMPLE_host'}) || !defined($ftp_data{'SAMPLE_user'}) || !defined($ftp_data{'SAMPLE_password'}) ) { # don't even try print LOG "file $ftp_data doesn't have what we need!\n"; exit 1; } use Net::SFTP; $now_string = localtime(); printf LOG "\tsftp: Starting $now_string \n"; my %args = (ssh_args => []); $args{debug} = 1; $args{user} = $ftp_data{'SAMPLE_user'}; $args{password} = $ftp_data{'SAMPLE_password'}; $sftp = Net::SFTP->new($ftp_data{'SAMPLE_host'},%args); if(! $sftp ) { print LOG "failed: connection to host $ftp_data{'SAMPLE_host'}\n"; } else { $herename = $ARGV[0]; $therename = $ARGV[1]; printf LOG "sending file %s to %s\n", $herename, $therename; if(! $sftp->put($herename,$therename) ) { print LOG "failed: put $herename to $therename\n"; } else { printf LOG "sent file %s to %s\n", $herename, $therename; } } $now_string = localtime(); print LOG "\tftp: Finished $now_string \n"; exit 0; -----Original Message----- From: Howard, Chris Sent: Thursday, January 22, 2009 11:29 AM To: Howard, Chris; ssh...@li... Subject: RE: [Ssh-sftp-perl-users] help needed with SFTP followup to myself: I think I have the basic script working ok now. |