Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SFTP from Perl for Windows

957 views
Skip to first unread message

Ashley Cooper

unread,
Aug 26, 2009, 10:13:00 PM8/26/09
to begi...@perl.org
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 have tried installing Net::SFTP::Foreign via ppm but it apparently
relies on having an ssh command that it can call to establish a
connection to start with. I have not been able to find a Windows ssh
command that can be used as a batch command (as opposed to a GUI).

I tried installing LWP::Protocol::sftp but it seems to end up calling
the above module and so still needs an ssh command.

I also tried to manually install Net:FTPSSL (and its dependants
IO::Socket:SSL and Net::SSLeay), none of which seem to be available on
ActiveState, but this requires a "make", a command which Windows doesn't
seem to have (I usually work in Unix).

Can anyone suggest how to get one of the above options to work in
Windows? Or a different option?

Thanks and regards,

Ashley


***********************************************************************************
This e-mail, including any attachments to it, may contain confidential and/or personal information. If you have received this e-mail in error, you must not copy, distribute, or disclose it, use or take any action based on the information contained within it. Please notify the sender immediately by return e-mail of the error and then delete the original e-mail.

The information contained within this e-mail may be solely the opinion of the sender and may not necessarily reflect the position, beliefs or opinions of the organisation on any issue. This email has been swept for the presence of computer viruses known to the organisation’s anti-virus systems.

***********************************************************************************


Sisyphus

unread,
Aug 26, 2009, 11:10:34 PM8/26/09
to Ashley Cooper, begi...@perl.org

----- Original Message -----
From: "Ashley Cooper" <Ashley...@salmat.com.au>
To: <begi...@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

Ashley Cooper

unread,
Aug 26, 2009, 11:37:31 PM8/26/09
to Sisyphus, begi...@perl.org
I can see a Net::SSH on ActiveState, but not Net::SSH2. Is this the same thing?

Regards,
@shley
Hmmm ... not a very good adaptation - it actually uses scp, and $sftp is
used only once.
See how you get on with it.

Cheers,
Rob

Sisyphus

unread,
Aug 26, 2009, 11:29:39 PM8/26/09
to Ashley Cooper, begi...@perl.org

Hmmm ... not a very good adaptation - it actually uses scp, and $sftp is

Sisyphus

unread,
Aug 27, 2009, 1:56:50 AM8/27/09
to Ashley Cooper, begi...@perl.org

----- Original Message -----
From: "Ashley Cooper" <Ashley...@salmat.com.au>
To: "Sisyphus" <sisy...@optusnet.com.au>; <begi...@perl.org>
Sent: Thursday, August 27, 2009 1:37 PM
Subject: RE: SFTP from Perl for Windows


>I can see a Net::SSH on ActiveState, but not Net::SSH2. Is this the same
>thing?

No, it's different - and there's no Net::SSH2 on the ActiveState ppm
repository.
If you want to give Net::SSH2 a try, just run the ppm command (that I posted
in my first reply) that's appropriate for the version of perl that you have.

Cheers,
Rob

David Christensen

unread,
Aug 27, 2009, 2:09:53 AM8/27/09
to begi...@perl.org, Ashley Cooper
Ashley Cooper wrote:
> 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.
> ...
> Can anyone suggest ... a different option?

Cygwin and Cygwin Perl and OpenSSH packages:

http://cygwin.org/


I have a mixed Windows/ Cygwin and Debian GNU/ Linux SOHO network and Ubuntu GNU/ Linux web hosting accounts, and built a backup/ archive/ shutdown solution using Bash and Perl scripts driving tar, gzip, and rsync over ssh.


HTH,

David


Ashley Cooper

unread,
Aug 27, 2009, 8:53:33 PM8/27/09
to Sisyphus, begi...@perl.org
Unfortunately I forgot to mention a crucial point about the function I am trying to code for.

The source Windows server from which the files have to be copied is external to our organisation - the server belongs to a third party. The server is open for SFTP transfers on a specified port only, so any solution requiring an SSH connection is not going to work - unless the third party changes their architecture which is unlikely.

My reading of this is that any solution that requires an SSH connection (including NET::SFTP::Foreign and other ActiveState modules which explicitly call an ssh executable to establish a connection) is not going to fly.

The module Net:FTPSSL would appear to be a solution but it is not on ActiveState and attempts to download and install it manually from CPAN have failed.

So I am still open to any alternative solutions, or words of advice from anyone who has managed to successfully install Net::FTPSSL.

Regards,
@shley

-----Original Message-----
From: Sisyphus [mailto:sisy...@optusnet.com.au]
Sent: Thursday, 27 August 2009 1:30 PM
To: Ashley Cooper; begi...@perl.org

r...@i.frys.com

unread,
Aug 27, 2009, 9:20:31 PM8/27/09
to Ashley Cooper, begi...@perl.org
Ashley Cooper wrote:
> Unfortunately I forgot to mention a crucial point about
> the function I am trying to code for.
>
> The source Windows server from which the files have to be
> copied is external to our organisation - the server
> belongs to a third party. The server is open for SFTP
> transfers on a specified port only, so any solution
> requiring an SSH connection is not going to work - unless
> the third party changes their architecture which is
> unlikely.
>
> My reading of this is that any solution that requires an
> SSH connection (including NET::SFTP::Foreign and other
> ActiveState modules which explicitly call an ssh
> executable to establish a connection) is not going to fly.
>
> The module Net:FTPSSL would appear to be a solution but it
> is not on ActiveState and attempts to download and install
> it manually from CPAN have failed.
>
> So I am still open to any alternative solutions, or words
> of advice from anyone who has managed to successfully
> install Net::FTPSSL.
>
> Regards,
> @shley
>

You need to add additional ppm repositories. You can find
Net::FTPSSL on either the Trouchelle or University of
Winnipeg repositories.

http://ppm4.activestate.com/


--
Ron


Ashley Cooper

unread,
Aug 27, 2009, 10:20:39 PM8/27/09
to r...@i.frys.com, begi...@perl.org
You beauty! I am new to this whole ppm thing, and didn't know about the
additional repositories.

I have now been able to install the FTLSSL module I originally wanted
and make some progress at last.

Thanks a million. :-)

@shley

http://ppm4.activestate.com/


--
Ron

***********************************************************************************

0 new messages