cc has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use warnings; use File::Copy; use File::Find; use Net::Netrc; use Net::SFTP; use MIME::Lite; use Getopt::Std; use Mail::Sender; my $server = "X.X.X.X"; my $user = "myuser"; my $password = ""; my %args = (ssh_args => []); $args{debug} = 1; $args{user} = "myuser"; # file my $file = "/srv/*.txt"; # ftp directories my $remote_directory = ""; my $linux = "admin\@domain.net"; my $recipient1 = "recipient1\@domain.net"; my $recipient2 = "recipient2\@domain.net"; my $recipient3 = "recipient3\@domain.net>"; # write the log BEGIN { use CGI::Carp qw(carpout); my $errorlog = "/srv/logs/transferlog.txt"; open(LOG, ">$errorlog") or die("Unable to open $errorlog: $!\n"); print LOG "Errors:\n"; carpout(*LOG); } # create backup subfolder my @dt = localtime; my $subfolder_name = ((((1900 + $dt[5]) * 100 + 1 + $dt[4]) * 100 + $d +t[3]) * 100 + $dt[2]) * 100 + $dt[1]; mkdir "/srv/OUT/$subfolder_name" or die "$subfolder_name: $!"; foreach my $file (</srv/*.txt>) { # sftp transfer my $sftp=Net::SFTP->new($server, %args) or die "could not open + connection to $server\n"; # change remote directory for the first file # $sftp->cd($remote_directory); # $sftp->binary; $sftp->put($file, $file) or die "could not upload a file\n"; #quit SFTP #$sftp->quit; # move to the backup directory unless(move("$file", "/srv/OUT/$subfolder_name")) { print STDERR "Oops! Couldn't move the file: $!"; } move "/srv/logs/transferlog.txt", "/srv/OUT/$subfolder_name"; sleep (1 * 5) } # send the mail, when transfer completed my $sender = new Mail::Sender {smtp => 'localhost', from => $linux}; $sender->MailFile({to => "$recipient1, $recipient2, $recipient3", subject => 'data transfer', msg => 'data transfer should be completed', file => "/srv/OUT/$subfolder_name/transferlog.txt"}); exit;
linux: Next method to try is publickey. Permission denied at /usr/local/share/perl/5.10.0/Net/SFTP.pm line 62
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: transfer a file via SFTP
by ig (Vicar) on Jul 23, 2009 at 01:01 UTC | |
by cc (Beadle) on Jul 23, 2009 at 22:42 UTC | |
by ig (Vicar) on Jul 24, 2009 at 06:24 UTC | |
by cc (Beadle) on Jul 24, 2009 at 17:45 UTC | |
by ig (Vicar) on Jul 24, 2009 at 21:49 UTC | |
| |
|
Re: transfer a file via SFTP
by salva (Canon) on Jul 30, 2009 at 07:22 UTC | |
by adarsh g u (Initiate) on Feb 05, 2020 at 02:58 UTC | |
by salva (Canon) on Feb 08, 2020 at 10:29 UTC | |
by hippo (Archbishop) on Feb 05, 2020 at 09:39 UTC |