<?xml version="1.0" encoding="windows-1252"?>
<node id="949805" title="ActivePerl - perl.exe works, wperl.exe does not..." created="2012-01-24 21:39:06" updated="2012-01-24 21:39:06">
<type id="115">
perlquestion</type>
<author id="739210">
spstansbury</author>
<data>
<field name="doctext">
&lt;p&gt;Greetings Monks.&lt;/p&gt;&lt;p&gt;I'm hoping someone with more ActivePerl experience that I can shed some light on the behavior that I'm seeing.&lt;/p&gt;&lt;p&gt;I have a script ( below ) that copies some Nessus scans to another machine for further processing.&lt;/p&gt;
&lt;p&gt;When I run the script via perl.exe ( &lt;code&gt;&gt;perl copy_files.wpl&lt;/code&gt; ) it runs perfectly.&lt;/p&gt;
&lt;p&gt;When I run it via wperl.exe, either on the command line ( &lt;code&gt;&gt;wperl copy_files.wpl&lt;/code&gt; ) or via Windows Task Scheduler, it fails with the error: &lt;code&gt;Unable to connect to remote host: Bad ssh command: Invalid argument at C:\Users\Administrator\RiskView\copy_files.wpl line 76.&lt;/code&gt;
&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;As always, thanks for any input!&lt;/p&gt;
&lt;p&gt;Best regards, Scott...&lt;/p&gt;

&lt;p&gt;file_copy.wpl:&lt;/p&gt;
&lt;code&gt;

use strict;
use warnings;

use Date::Manip;
use Archive::Zip;
use Net::SFTP::Foreign;
use Data::Dumper;

BEGIN {
	Win32::SetChildShowWindow(0) if defined &amp;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, "&gt;&gt;$output_log");

close(STDERR);
open(STDERR, "&gt;&gt;$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, "&lt;$copy_log");

while ( my $line = &lt;LOG_DATA&gt;) {
	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-&gt;new_date;
my $now_date = $dm1-&gt;new_date;

my $time_stamp = time;
my $err = $now_date-&gt;parse( "epoch $time_stamp" );
my $current_date = $now_date-&gt;printf( "%Y-%m-%d %H:%M:%S" );

$last_loaded_date =~ s/^\s+//;
$last_loaded_date =~ s/\s+$//;

$dm1-&gt;parse( $last_loaded_date ); 

my $sftp = Net::SFTP::Foreign-&gt;new( $host, user =&gt; $user, password =&gt; $password, ssh_cmd =&gt; 'plink' );
$sftp-&gt;error and die "Unable to connect to remote host: " . $sftp-&gt;error;

# Get the files
chdir $incoming_dir;

my @ls1 = @{ $sftp-&gt;ls( $nessus_dir, names_only =&gt; 1, ordered =&gt; 1 ) };
my $last_loaded;

foreach my $dir_date ( @ls1 ) {
	next unless $dir_date =~ /\d{4}-\d{2}-\d{2}/;

	$dm2-&gt;parse( $dir_date );
	if ( $dm1-&gt;cmp( $dm2 ) == -1 ) {
		$sftp-&gt;mget( "$nessus_dir/$dir_date/*nessus-results.zip" ) or die "Unable to transfer files: " . $sftp-&gt;error;
		$last_loaded = $dir_date;
		print "Getting files from directory $dir_date\n";
	}
}

undef $sftp;

open( LOG,"&gt;../$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 );
&lt;/code&gt;

</field>
</data>
</node>
