From: Schwartz, Peter W
Sent: Tuesday, October 28, 2014 2:44 AM
To: perl...@listserv.ActiveState.com
Subject: SFTP
> I’m trying to locate an SFTP install for Windows (32-bit) but I can’t seem > to find anything in the PPM for some reason. Does anyone have any > recommendations on how to get this for Windows?
You can do SFTP with Net::SSH2 - which is now part of Strawberry Perl.
Or, if you don't have Net::SSH2 you can:
ppm install http://www.sisyphusion.tk/ppm/Net-SSH2.ppd --force
However, the Net::SSH2 user interface is a bit awkward, so the nicest way to
utilise that module (and this is how I use it) is to then:
ppm install http://www.sisyphusion.tk/ppm/Net-SFTP-Foreign.ppd --force
ppm install
http://www.sisyphusion.tk/ppm/Net-SFTP-Foreign-Backend-Net_SSH2.ppd --force
(Those last 2 are pure-perl and just as simple to install using 'cpan -i' or
similar, if you want. The reason we use --force is explained at
http://www.sisyphusion.tk/faq.html )
That done, it's just a matter of something like:
#############################################
use strict;
use warnings;
use Net::SFTP::Foreign;
$ftp = Net::SFTP::Foreign->new
(host => $server,
backend => 'Net_SSH2',
user => $user,
password => $pass,
);
$ftp->error and die "Unable to establish SFTP connection: ". $ftp->error;
print "Connected to the SFTP server (and authorised)\n";
$ftp->put($local_file, $remote_file) or die $ftp->error;
$ftp->get($rem_file, $loc_file) or die $ftp->error;
$ftp->disconnect;
#############################################
Works well for me.
Cheers,
Rob
_______________________________________________
Perl-Win32-Users mailing list
Perl...@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs