use strict; use warnings; use Date::Manip; use Archive::Zip; use Net::SFTP::Foreign; use Data::Dumper; BEGIN { Win32::SetChildShowWindow(0) if defined &Win32::SetChildShowWindow; } my $producer = "file_copy" my $output_log = $producer . "_output_log.log"; unlink( $output_log ); close(STDOUT); open(STDOUT, ">>$output_log" ); close(STDERR); open(STDERR, ">>$output_log" ); # Nessus directory my $nessus_dir = '/opt/sc4/orgs/1/VDB'; my $incoming_dir = 'C:\\Users\\Administrator\\Incoming'; # Data file directory my $data_dir = 'C:\\Users\\Administrator\\Data'; my $host = '255.255.255.255'; my $user = 'xxxxxxx'; my $password = 'xxxxxxx'; # Find the target results directory - look for yesterday's results my $yesterday = ( time - 86400 ); my $dm = Date::Manip::Date->new; $dm->parse( "epoch $yesterday" ); my $daily_results_dir = $dm->printf( "%Y-%m-%d" ); # Change this to load specific day's results $daily_results_dir = "2011-09-10"; no warnings 'Net::SFTP::Foreign'; my $sftp = Net::SFTP::Foreign->new( $host, user => $user, password => $password, ssh_cmd => 'plink' ); $sftp->error and die "Unable to connect to remote host: " . $sftp->error; # Get the files $sftp->mget( "$nessus_dir/$daily_results_dir/*nessus-results.zip", "$incoming_dir"); undef $sftp; # unzip the files. chdir $data_dir; opendir ( INCOMING_FILES, $incoming_dir ) or die "Can't open directory $incoming_dir: $!"; for ( readdir INCOMING_FILES ) { next unless $_ =~ /zip$/; print "$_\n"; my $az = Archive::Zip->new( "$incoming_dir\\$_" ); $az->extractTree(); } # Delete the zipped files in the Incoming directory unlink ( glob ( "$incoming_dir\\*nessus-results.zip")) or warn "can't delete files: $!";