]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/net_ssh2_ls.pl
Executable scripts
[working/Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / net_ssh2_ls.pl
1 #!/usr/bin/perl -IOpen-ILS/src/perlmods 
2
3 use strict; use warnings;
4
5 use Net::SSH2;
6 use Data::Dumper;
7
8 my $delay = 1;
9
10 my %config = (
11     remote_host => 'example.org',
12     remote_user => 'some_user',
13     remote_password => 'whatever',
14 );
15
16 $config{remote_file} = '/home/' . $config{remote_user};
17
18 my $x = Net::SSH2->new();
19
20 $x->connect($config{remote_host}) or die "Could not connect to $config{remote_host}: " . $x->error;
21 $x->auth(
22     publickey  => '/home/opensrf/.ssh/id_rsa.pub',
23     privatekey => '/home/opensrf/.ssh/id_rsa',
24     username   => $config{remote_user},
25 #    password   => $config{remote_password},
26     rank => [ qw/ publickey hostbased password / ],
27 ) or die "Auth failed for $config{remote_host}: " . $x->error;
28
29 print "Reading directory: $config{remote_file}\n";
30 my $sftp = $x->sftp;
31 my $dir = $sftp->opendir($config{remote_file}) or die $sftp->error;
32
33 print "Directory listing:\n";
34 my $i = 0;
35 while (my $line = $dir->read()) {
36     printf "%3s)\n", ++$i;
37     foreach (sort keys %$line) {
38         printf "   %20s => %s\n", $_, $line->{$_};
39     }
40 }
41
42 exit;
43