sub copy_file_local { my $srv = $conf->get("proxy_server"); $logger->info("Making SCP connection to $srv"); my $ssh = Net::SSH2->new(); my $start_time = $conf->get('start_time'); $ssh->connect($srv); $ssh->auth_publickey( $conf->get('uid'), $conf->get('pubkey'), $conf->get('privkey') ) or die $!; foreach my $file (@_) { my $target = catfile($conf->get('local_storage'), "${start_time}_$file"); $logger->info("Copying $file to $target"); my $success = 0; my $attempts = 0; while (!$success && $attempts < 3) { $attempts++; $ssh->scp_get($file, $target); $logger->info("Gathering file data..."); my @remote_stat = split /\|/, $control->cmd("perl -e 'print join(\"|\", stat(\"$file\")), \"\\n\"'") ; my @local_stat = stat($target); if ($remote_stat[7] == $local_stat[7]) { $success = 1; $logger->info("File sizes match."); last; } } $logger->info("Deleting $file from remote."); $control->cmd("rm $file"); } $ssh->disconnect(); }