Net::SSH2::Channel - SSH 2 channel object


Net-SSH2 documentation Contained in the Net-SSH2 distribution.

Index


Code Index:

NAME

Top

Net::SSH2::Channel - SSH 2 channel object

DESCRIPTION

Top

A channel object is created by the Net::SSH2 channel method. As well as being an object, it is also a tied filehandle. The Net::SSH2 poll method can be used to check for read/write availability and other conditions.

setenv ( key, value ... )

Sets remote environment variables. Note that most implementations do not allow environment variables to be freely set. Pass in a list of keys and values with the values to set. Returns the number of successful sets.

blocking ( flag )

Enable or disable blocking. Note that this is currently implemented in libssh2 by setting a per-session flag; it's equivalent to Net::SSH2::blocking.

eof

Returns true if the remote server sent an EOF.

send_eof

Send an EOF to the remote. After an EOF has been sent, no more data may be sent; the connection should be closed.

close

Close the channel (happens automatically on object destruction).

wait_closed

Wait for a remote close event. Must have already seen remote EOF.

exit_status

Returns the channel's program exit status.

pty ( terminal [, modes [, width [, height ]]] )

Request a terminal on a channel. If provided, width and height are the width and height in characters (defaults to 80x24); if negative their absolute values specify width and height in pixels.

pty_size ( width, height )

Request a terminal size change on a channel. width and height are the width and height in characters; if negative their absolute values specify width and height in pixels.

process ( request, message )

Start a process on the channel. See also shell, exec, subsystem.

shell

Start a shell on the remote host; calls process("shell").

exec ( command )

Execute the command on the remote host; calls process("exec", command). Note that only one of these requests can succeed per channel (cp. exec in perlfunc); if you want to run a series of commands, consider using shell instead.

subsystem ( name )

Run subsystem on the remote host; calls process("subsystem", command).

ext_data ( mode )

Set extended data handling mode:

normal (default)

Keep data in separate channels; stderr is read separately.

ignore

Ignore all extended data.

merge

Merge into the regular channel.

read ( buffer, size [, ext ] )

Attempts to read size bytes into the buffer. Returns number of bytes read, undef on failure. If ext is present and set, reads from the extended data channel (stderr).

write ( buffer [, ext ] )

Attempts to write the buffer to the channel. Returns number of bytes written, undef on failure. If ext is present and set, writes to the extended data channel (stderr).

flush ( [ ext ] )

Flushes the channel; if ext is present and set, flushes extended data channel. Returns number of bytes flushed, undef on error.

exit_signal

Returns the exit signal of the command executed on the channel. Requires libssh 1.2.8 or higher.

SEE ALSO

Top

Net::SSH2.

AUTHOR

Top

David B. Robins, <dbrobins@cpan.org>

COPYRIGHT AND LICENSE

Top


Net-SSH2 documentation Contained in the Net-SSH2 distribution.

package Net::SSH2::Channel;

use strict;
use warnings;
use Carp;

# methods

sub shell {
    $_[0]->process('shell')
}

sub exec {
    $_[0]->process(exec => $_[1])
}

sub subsystem {
    $_[0]->process(subsystem => $_[1])
}

sub error {
    shift->session->error(@_)
}


# tie interface

sub PRINT {
    my $self = shift;
    my $sep = defined($,) ? $, : '';
    $self->write(join $sep, @_)
}

sub PRINTF {
    my $self = shift;
    $self->write(sprintf @_)
}

sub WRITE {
    my ($self, $buf, $len, $offset) = @_;
    $self->write(substr($buf, $offset, $len))
}

sub READLINE {
    my $self = shift;
    return if $self->eof;

    if (wantarray) {
        my @lines;
        my $line;
        push @lines, $line while defined($line = $self->READLINE);
        return @lines;
    }
    
    my ($line, $eol, $c) = ('', $/);
    $line .= $c while $line !~ /\Q$eol\E$/ and defined($c = $self->GETC);
    length($line) ? $line : undef
}

sub GETC {
    my $self = shift;
    my $buf;
    my @poll = ({ handle => $self, events => 'in' });
    return
     unless $self->session->poll(250, \@poll) and $poll[0]->{revents}->{in};
    $self->read($buf, 1) ? $buf : undef
}

sub READ {
    my ($self, $rbuf, $len, $offset) = @_;
    my ($tmp, $count);
    return unless defined($count = $self->read($tmp, $len));
    substr($$rbuf, $offset) = $tmp;
    $count
}

sub CLOSE {
    &close
}

sub BINMODE {
}

sub EOF {
    &eof
}

1;
__END__