Net::SSH::W32Perl - MSWin32 compatibility layer for Net::SSH::Perl


Net-SSH-W32Perl documentation Contained in the Net-SSH-W32Perl distribution.

Index


Code Index:

NAME

Top

Net::SSH::W32Perl - MSWin32 compatibility layer for Net::SSH::Perl

SYNOPSIS

Top

 use Net::SSH::W32Perl;

 my $host = 'foo.bar.com';
 my $ssh = new Net::SSH::W32Perl($host, [options]);
 $ssh->login('user', 'password');
 my ($out, $err, $exit) = $ssh->cmd('cat', 'Hello Net::SSH::W32Perl User!');

DESCRIPTION

Top

This module provides limited Net::SSH::Perl functionality under MSWin32 (ActivePerl). See Net::SSH::Perl for a functional description.

When used on non-MSWin32 systems, Net::SSH::W32Perl reverts to traditional Net::SSH::Perl functionality.

SSH2 is the default protocol under MSWin32. Specifying a protocol other than SSH2 will cause SSH2 to die() - see below.

LIMITATIONS

Top

TO DO

Top

Integrate the Net::SSH::Perl tests, fix privileged, etc...

AUTHOR & COPYRIGHT

Top

SEE ALSO

Top

Net::SSH::Perl


Net-SSH-W32Perl documentation Contained in the Net-SSH-W32Perl distribution.

package Net::SSH::W32Perl;

use strict;
use Carp;

use IO::Socket;

use Net::SSH::Perl;
use Net::SSH::Perl::Constants qw( :protocol );
use constant DEFAULT_SSH_PORT => '22';
use constant IS_WIN32 => ($^O =~ /MSWin32/i);

use vars qw/ $VERSION @ISA/;
$VERSION = '0.05';

@ISA = qw/Net::SSH::Perl/;

sub _init {
	my $ssh = shift;
	my %arg = @_;

   $arg{protocol} = 2 unless exists $arg{protocol};

    $ssh->SUPER::_init(%arg);
}

sub _connect {
    my $ssh = shift;
    return $ssh->SUPER::_connect(@_) unless IS_WIN32;

    my $rport = $ssh->{config}->get('port') || DEFAULT_SSH_PORT;
    my $rhost = $ssh->{host};

    $ssh->debug("Connecting to $ssh->{host}, port $rport.");
    my $sock = IO::Socket::INET->new(
    	PeerAddr => $rhost,
        PeerPort => $rport,
        Proto    => 'tcp'
    ) || die "Can't connect to $rhost: $!\n";
	
    $ssh->{session}{sock} = $sock;

	my $t = $|;
	$| = 0;
    $ssh->debug("Socket created, turning on blocking...");
    $sock->blocking(1);
    $ssh->_exchange_identification;
    $sock->blocking(0);
	$| = $t;

    $ssh->debug("Connection established.");
}

sub protocol_class {
    return shift->SUPER::protocol_class(@_) unless IS_WIN32;
    
    die "SSH2 is the only supported protocol under MSWin32!"
        unless (PROTOCOL_SSH2 == $_[1]);
        
	return 'Net::SSH::W32Perl::SSH2';
}

sub Close {}

1;
__END__