GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Net::SSH2::Channel(3) User Contributed Perl Documentation Net::SSH2::Channel(3)

Net::SSH2::Channel - SSH2 channel object

  my $chan = $ssh2->channel()
    or $ssh2->die_with_error;

  $chan->exec("ls -ld /usr/local/libssh2*")
    or $ssh2->die_with_error;

  $chan->send_eof;

  while (<$chan>) {
    print "line read: $_";
  }

  print "exit status: " . $chan->exit_status . "\n";

A channel object is created by the Net::SSH2 "channel" method. As well as being an object, it is also a tied filehandle.

Sets remote environment variables. Note that most servers do not allow environment variables to be freely set.

Pass in a list of keys and values with the values to set.

It returns a true value if all the given environment variables were correctly set.

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.

Returns true if the remote server sent an EOF.

Sends an EOF to the remote side.

After an EOF has been sent, no more data may be sent to the remote process "STDIN" channel.

Note that if a PTY was requested for the channel, the EOF may be ignored by the remote server. See "pty".

Close the channel (happens automatically on object destruction).

Wait for a remote close event.

In order to avoid a bug in libssh2 this method discards any unread data queued in the channel.

Returns the channel's program exit status.

This method blocks until the remote side closes the channel.

Request a terminal on a channel.

"terminal" is the type of emulation (e.g. vt102, ansi, etc...).

"modes" are the terminal mode modifiers, for instance:

    $c->pty('vt100', { echo => 0, vintr => ord('k') });

The list of acceptable mode modifiers is available from the SSH Connection Protocol RFC (RFC4254 <https://tools.ietf.org/html/rfc4254#section-8>).

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.

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.

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.

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

Note that only one invocation of "process" or any of the shortcuts "shell", "exec" or "subsystem" is allowed per channel. In order to run several commands, shells or/and subsystems, a new "Channel" instance must be used for every one.

Alternatively, it is also possible to launch a remote shell (using shell) and simulate the user interaction printing commands to its "stdin" stream and reading data back from its "stdout" and "stderr". But this approach should be avoided if possible; talking to a shell is difficult and, in general, unreliable.

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

Execute the command on the remote host (calls "process("exec", command)").

Note that the given command is parsed by the remote shell; it should be properly quoted, specially when passing data from untrusted sources.

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

Attempts to read up to "max_size" bytes from the channel into "buffer". If "ext" is true, reads from the extended data channel ("STDERR").

The method returns as soon as some data is available, even if the given size has not been reached.

Returns number of bytes read or "undef" on failure. Note that 0 is a valid return code.

Attempts to read from both the ordinary (stdout) and the extended (stderr) channel streams.

Returns two scalars with the data read both from stdout and stderr. It returns as soon as some data is available and any of the returned values may be an empty string.

When some error happens it returns the empty list.

Example:

  my ($out, $err) = ('', '');
  while (!$channel->eof) {
      if (my ($o, $e) = $channel->read2) {
          $out .= $o;
          $err .= $e;
      }
      else {
          $ssh2->die_with_error;
      }
  }
  print "STDOUT:\n$out\nSTDERR:\n$err\n";

Reads the next line from the selected stream ("ext" defaults to 0: stdout).

$/ is used as the end of line marker when "eol" is "undef".

In list context reads and returns all the remaining lines until some read error happens or the remote side sends an eof.

Note that this method is only safe when the complementary stream (e.g. "!ext") is guaranteed to not generate data or when "ext_data" has been used to discard or merge it; otherwise it may hang. This is a limitation of libssh2 that hopefully would be removed in a future release, in the meantime you are advised to use read2 instead.

Reads and returns the next character from the selected stream.

Returns "undef" on error.

Note that due to some libssh2 quirks, the return value can be the empty string which may indicate an EOF condition (but not always!). See "eof".

Send the data in "buffer" through the channel. Returns number of bytes written, undef on failure.

In versions of this module prior to 0.57, when working in non-blocking mode, the would-block condition was signaled by returning "LIBSSH2_ERROR_EAGAIN" (a negative number) while leaving the session error status unset. From version 0.59, "undef" is returned and the session error status is set to "LIBSSH2_ERROR_EAGAIN" as for any other error.

In non-blocking mode, if "write" fails with a "LIBSSH2_ERROR_EAGAIN" error, no other operation must be invoked over any object in the same SSH session besides "sock" and blocking_directions.

Once the socket becomes ready again, the exact same former "write" call, with exactly the same arguments must be invoked.

Failing to do that would result in a corrupted SSH session. This is a limitation in libssh2.

Discards the received but still unread data on the channel; if "ext" is present and set, discards data on the extended channel. Returns number of bytes discarded, "undef" on error.

Returns the name of exit signal from the remote command.

In list context returns also the error message and a language tag, though as of libssh2 1.7.0, those values are always undef.

This method blocks until the remote side closes the channel.

Converts the signal name to a signal number using the local mapping (which may be different to the remote one if the operating systems differ).

Returns the number of bytes which the remote end may send without overflowing the window limit.

In list context it also returns the number of bytes that are immediately available for read and the size of the initial window.

Returns the number of bytes which may be safely written to the channel without blocking at the SSH level. In list context it also returns the size of the initial window.

Note that this method doesn't take into account the TCP connection being used under the hood. Getting a positive integer back from this method does not guarantee that such number of bytes could be written to the channel without blocking the TCP connection.

Adjust the channel receive window by the given "adjustment" bytes.

If the amount to be adjusted is less than "LIBSSH2_CHANNEL_MINADJUST" and force is false the adjustment amount will be queued for a later packet.

On success returns the new size of the receive window. On failure it returns "undef".

Net::SSH2.
2020-04-17 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.