Greetings Monks.
I'm hoping someone with more ActivePerl experience that I can shed some light on the behavior that I'm seeing.
I have a script ( below ) that copies some Nessus scans to another machine for further processing.
When I run the script via perl.exe ( >perl copy_files.wpl ) it runs perfectly.
When I run it via wperl.exe, either on the command line ( >wperl copy_files.wpl ) or via Windows Task Scheduler, it fails with the error: Unable to connect to remote host: Bad ssh command: Invalid argument at C:\Users\Administrator\RiskView\copy_files.wpl line 76.
I believe I have all the required tweaks for wperl - suppressing the window, redirecting STDERR and STDOUT to files, but as wperl.exe is supposed to be identical to perl.exe except for the need to launch a window, I'm at a loss to explain why it won't run the Net::SFTP::Foreign module without error.
As always, thanks for any input!
Best regards, Scott...
file_copy.wpl:
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";
my $error_log = $producer . "_error_log.log";
my $copy_log = $producer . "_log.log";
unlink( $error_log );
unlink( $output_log );
close(STDOUT);
open(STDOUT, ">>$output_log");
close(STDERR);
open(STDERR, ">>$error_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 = '10.10.10.10';
my $user = 'user';
my $password = 'password';
# Check the copylog for the last set of files loaded
my $last_loaded_date;
open ( LOG_DATA, "<$copy_log");
while ( my $line = <LOG_DATA>) {
chomp $line;
next unless( $line =~ /Last Loaded/ );
my @last_loaded_time_line = split( /:/, $line );
$last_loaded_date = $last_loaded_time_line[1];
last;
}
close ( LOG_DATA);
print "Getting files more recent than $last_loaded_date\n";
my $dm1 = new Date::Manip::Date;
my $dm2 = $dm1->new_date;
my $now_date = $dm1->new_date;
my $time_stamp = time;
my $err = $now_date->parse( "epoch $time_stamp" );
my $current_date = $now_date->printf( "%Y-%m-%d %H:%M:%S" );
$last_loaded_date =~ s/^\s+//;
$last_loaded_date =~ s/\s+$//;
$dm1->parse( $last_loaded_date );
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->err
+or;
# Get the files
chdir $incoming_dir;
my @ls1 = @{ $sftp->ls( $nessus_dir, names_only => 1, ordered => 1 ) }
+;
my $last_loaded;
foreach my $dir_date ( @ls1 ) {
next unless $dir_date =~ /\d{4}-\d{2}-\d{2}/;
$dm2->parse( $dir_date );
if ( $dm1->cmp( $dm2 ) == -1 ) {
$sftp->mget( "$nessus_dir/$dir_date/*nessus-results.zip" ) or
+die "Unable to transfer files: " . $sftp->error;
$last_loaded = $dir_date;
print "Getting files from directory $dir_date\n";
}
}
undef $sftp;
open( LOG,">../$copy_log ") or die $!;
print LOG "Copied Nessus reports from SecurityCenter\n";
print LOG "Last copy run on: $current_date\n";
print LOG "Last Loaded (directory name): $last_loaded\n";
close( LOG );