develooper Front page | perl.beginners | Postings from August 2009

Re: SFTP from Perl for Windows

Thread Previous | Thread Next
From:
Sisyphus
Date:
August 26, 2009 20:11
Subject:
Re: SFTP from Perl for Windows
Message ID:
3FB2B8FF15074410A0650432ED9C71DB@desktop2

----- Original Message ----- 
From: "Ashley Cooper" <Ashley.Cooper@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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About