calmthestorm has asked for the wisdom of the Perl Monks concerning the following question:
The batch file contents are equally simple for testing purposes.#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::SSH::Perl question
by quester (Vicar) on Oct 30, 2008 at 06:40 UTC | |
by calmthestorm (Acolyte) on Oct 30, 2008 at 18:59 UTC |