#!/usr/bin/perl -w use strict; use Net::SFTP; use Net::SSH::Perl; my %credentials = ( user => 'admin', password => 'admin.password'); my @hosts = ('hosta', 'hostb'); my $localfile = 'test.bat'; my $remotefile = 'remote_testfile'; my $local_dir = '/home/admin'; my $remote_dir = 'c:\Documents and Settings\admin'; my $sftp; my $ssh; foreach (@hosts) { $sftp = Net::SFTP->new($_, %credentials) || die; $sftp->put($localfile, "$remote_dir\\$localfile"); $sftp->get("$remote_dir\\$remotefile","$_.$remotefile"); undef $sftp; $ssh = Net::SSH::Perl->new($_) || die; $ssh->login($credentials{'user'}, $credentials{'password'}); my ($out, $err, $exit) = $ssh->cmd("$remote_dir\\$localfile"); undef $ssh; if ($out) { print "$out\n"; } if ($err) { print "Error: $err\n"; } print "Exit code: $exit\n"; } #### $ cat test.bat echo Executing the removal of remote_testfile del remote_testfile