Qore SSH2 Module  0.9.7
 All Classes Namespaces Functions
Qore SSH2 Module

Contents of this documentation:

Introduction

The ssh2 module provides Qore the possibility to communicate with sshd servers via the ssh2 protocol; the underlying functionality is provided by libssh2.

This module is released under the LGPL 2.1 and is tagged as such in the module's header (meaning it can be loaded unconditionally regardless of how the Qore library was initialized). This version of the module requires Qore 0.8.1+ to compile and run.

To use the module in a Qore script, use the %requires directive as follows:

%requires ssh2

This module provides the following classes:

Class Description
Qore::SSH2::SSH2Base base class for SFTPClient and SSH2Client
Qore::SSH2::SSH2Client allows Qore programs to establish an ssh2 connection to a remote server
Qore::SSH2::SFTPClient allows Qore programs to use the sftp protocol
Qore::SSH2::SSH2Channel allows Qore programs to send and receive data through an ssh2 channel

When connecting the module will try to:

See some examples here: Examples

Examples

Example of a basic sftp connection:

# create object
my SFTPClient $sftp("sftp://user:[email protected]:22");
# connect to sftp server
$sftp.connect();

Example of logging in via ssh2 and executing a command and retrieving the output:

# set URL
my string $url = "sftp://user:[email protected]:22";
# create object
my SSH2Client $ssh2($url);
# connect to remote sshd daemon
$ssh2.connect();
# get a session channel
my SSH2Channel $chan = $sc.openSessionChannel();
# execute a command on the channel
$chan.exec("ls -l");
# retrieve the output and print it out
stdout.printf("%s", $chan.read());
# close channel
$chan.sendEof();
$chan.close();
# print out the exit status after the channel is closed
stdout.printf("exit status: %d\n", $chan.getExitStatus());

Function and Method Tags

NOOP

Code with this flag makes no calculations, but rather returns a constant value. This flag is given to function and method variants that return a default value depending on the type of argument(s). When variants with this flag are resolved at parse time, a "call-with-type-errors" warning is raised (assuming this warning is enabled), unless PO_REQUIRE_TYPES or PO_STRICT_ARGS is set. If PO_REQUIRE_TYPES or PO_STRICT_ARGS is set, then these variants are inaccessible at parse time; resolving to a variant with this flag set at parse time causes an exception to be thrown.

These variants are included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments.

This tag is equal to RUNTIME_NOOP, except no runtime effect is caused by resolving a function or method tagged with NOOP at runtime; this tag only affects parse time resolution.

RUNTIME_NOOP

Code with this flag makes no calculations, but rather returns a constant value. This flag is given to function and method variants that return a default value depending on the type of argument(s). When variants with this flag are resolved at parse time, a "call-with-type-errors" warning is raised (assuming this warning is enabled), unless PO_REQUIRE_TYPES or PO_STRICT_ARGS is set. If PO_REQUIRE_TYPES or PO_STRICT_ARGS is set, then these variants are inaccessible; resolving to a variant with this flag set at parse time or run time causes an exception to be thrown.

These variants are included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments.

This tag is equal to NOOP, except that RUNTIME_NOOP is also enforced at runtime.

RET_VALUE_ONLY

This flag indicates that the function or method has no side effects; it only returns a value, for example.

This tag is identical to CONSTANT except that functions or methods tagged with RET_VALUE_ONLY could throw exceptions.

CONSTANT

This flag indicates that the function or method has no side effects and does not throw any exceptions.

This tag is identical to RET_VALUE_ONLY except that functions or methods tagged with CONSTANT do not throw exceptions.

DEPRECATED

Code with this flag is deprecated and may be removed in a future version of this module; if a variant with this flag is resolved at parse time, a "deprecated" warning is raised (assuming this warning is enabled).