----- Original Message ----- From: "Ashley Cooper" <ashley.coo...@salmat.com.au>
To: <beginners@perl.org>
Sent: Thursday, August 27, 2009 12:13 PM
Subject: SFTP from Perl for Windows


I need to be able to do file transfers via SFTP from Perl (ActiveState)
in a Windows environment but I am having trouble finding a suitable Perl
module that works.

===================================

I use Net::SSH2 on ActivePerl for just this purpose:

perl-5.10:
ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/Net-SSH2.ppd

perl-5.8:
ppm install http://theoryx5.uwinnipeg.ca/ppms/Net-SSH2.ppd
Adapted (and untested) from an actual script I use:
##############################
use warnings;
use strict;
use Net::SSH2;

my $server = 'server.nameer';
my $ssh2 = Net::SSH2->new;
die "can't connect" unless $ssh2->connect($server);

print "Connected\n";

die "can't authenticate"
unless $ssh2->auth(username => 'user',
                   password => 'pass');

print "Authenticated\n";

my $sftp = $ssh2->sftp;
$ssh2->debug(1);

my @files = qw (file1 file2 file3);
my $dir = '/directory/on/server';

#Upload
for(@files) {
  $ssh2->scp_put($_, "$dir/$_");
}

$ssh2->disconnect();
##########################

Cheers,
Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to