Qore SSH2 Module  1.0
Qore::SSH2::SSH2Client Class Reference

allows Qore programs to establish an ssh2 connection to a remote server More...

Inheritance diagram for Qore::SSH2::SSH2Client:

Public Member Functions

 constructor (string url, softint port=0)
 creates the object with the given hostname and port number More...
 
 copy ()
 throws an exception; currently SSH2Client objects cannot be copied More...
 
hash info ()
 returns a hash with information about the current connection status More...
 
SSH2Channel openDirectTcpipChannel (string host, softint port, string source_host="127.0.0.1", softint source_port=22, timeout timeout=60s)
 Opens a port forwarding channel and returns the corresponding SSH2Channel object for the new forwarded connection. More...
 
SSH2Channel openSessionChannel (timeout timeout=60s)
 Opens a login session and returns a SSH2Channel object for the session. More...
 
SSH2Channel scpGet (string path, timeout timeout=60s, *reference statinfo)
 opens a channel for retrieving a remote file with an optional timeout value and an optional reference for returning file status information More...
 
SSH2Channel scpPut (string remote_path, softint size, softint mode=0644, *date mtime, *date atime, timeout timeout=60s)
 Opens a channel for sending a file to the remote server; an SSH2Channel object is returned to use to send the file's data. More...
 
- Public Member Functions inherited from Qore::SSH2::SSH2Base
 clearStats ()
 Clears performance statistics. More...
 
nothing clearWarningQueue ()
 Removes any warning Queue object from the Socket. More...
 
nothing connect (timeout timeout=1m)
 connect to remote system More...
 
bool connected ()
 returns True if the session is connected, False if not More...
 
 constructor ()
 Throws an exception; the constructor cannot be called manually. More...
 
nothing disconnect (timeout timeout=1m)
 Disconnects from the remote system; throws an exception if the object is not currently connected. More...
 
hash getUsageInfo ()
 Returns performance statistics for the socket. More...
 
nothing setKeys (string priv_key, *string pub_key)
 Sets path to the private key and optionally the public key to use for the next connection; can only be called when a connection is not established, otherwise an exception is thrown. More...
 
nothing setPassword (string pass)
 Sets the password for the next connection; can only be called when a connection is not established, otherwise an exception is thrown. More...
 
nothing setUser (string user)
 Sets the user name for the next connection; can only be called when a connection is not established, otherwise an exception is thrown. More...
 
nothing setWarningQueue (int warning_ms, int warning_bs, Queue queue, any arg, timeout min_ms=1s)
 Sets a Queue object to receive socket warnings. More...
 

Detailed Description

allows Qore programs to establish an ssh2 connection to a remote server

Restrictions:
Qore::PO_NO_NETWORK

Member Function Documentation

Qore::SSH2::SSH2Client::constructor ( string  url,
softint  port = 0 
)

creates the object with the given hostname and port number

Parameters
urlthe remote host to connect to - can also be a url like "ssh://user:pass@hostname:port"
portthe port number on the remote host to connect to; if the port is 0, then the port given in the url argument is used; if none is given there, then the default port is used (22)
Exceptions
SSH2CLIENT-PARAMETER-ERRORempty url passed
Example:
my $ssh2client SSH2Client("host", 4022);
Qore::SSH2::SSH2Client::copy ( )

throws an exception; currently SSH2Client objects cannot be copied

Exceptions
SSH2CLIENT-COPY-ERRORcopying SSH2Client objects is not currently implemented
hash Qore::SSH2::SSH2Client::info ( )

returns a hash with information about the current connection status

this method is safe to call when not connected

Returns
a hash with the following keys:
  • ssh2host: (string) the host name of the remote server
  • ssh2port: (int) the port number of the remote server
  • ssh2user: (string) the user name used for the connection
  • keyfile_priv: (string) the filename of the local private key file used
  • keyfile_pub: (string) the filename of the local public key file used
  • fingerprint: (*string) The fingerprint of the public host key of the remote server as a string of hex digit pairs separated by colons (:), ex: "AC:AA:DF:3F:49:82:5A:1A:DE:C9:ED:14:00:7D:65:9E" or NOTHING if not connected
  • authenticated: (*string) a string giving the authentication mechanism used: "publickey", "password", "keyboard-interactive" or NOTHING if not connected
  • connected: (bool) tells if the connection is currently active or not
  • methods: (hash) a hash of strings giving the crytographic methods used for the connection
Code Flags:
CONSTANT
Example:
my hash $h = $ssh2client.info();
SSH2Channel Qore::SSH2::SSH2Client::openDirectTcpipChannel ( string  host,
softint  port,
string  source_host = "127.0.0.1",
softint  source_port = 22,
timeout  timeout = 60s 
)

Opens a port forwarding channel and returns the corresponding SSH2Channel object for the new forwarded connection.

Parameters
hostthe remote host to connect to
portthe port number on the remote host to connect to
source_hostthe host name to report as the source of the connection
source_portthe port number to report as the source of the connection
timeoutan integer giving a timeout in milliseconds or a relative date/time value (ex: 15s for 15 seconds)
Exceptions
SSH2CLIENT-OPENDIRECTTCPIPCHANNEL-ERRORport number for forwarded channel as second argument cannot be zero; source port number as fourth argument cannot be zero
SSH2CLIENT-NOT-CONNECTEDclient is not connected
SSH2CLIENT-TIMEOUTtimeout opening channel
SSH2-ERRORerror opening channel
Example:
my SS2Channel $chan = $ssh2client.("host", 4022, NOTHING, NOTHING, 30s);
SSH2Channel Qore::SSH2::SSH2Client::openSessionChannel ( timeout  timeout = 60s)

Opens a login session and returns a SSH2Channel object for the session.

Parameters
timeoutan integer giving a timeout in milliseconds or a relative date/time value (ex: 15s for 15 seconds)
Exceptions
SSH2CLIENT-NOT-CONNECTEDclient is not connected
SSH2CLIENT-TIMEOUTtimeout opening channel
SSH2-ERRORerror opening channel
Example:
my SSH2Channel $chan = $ssh2client.openSessionChannel(30s);
SSH2Channel Qore::SSH2::SSH2Client::scpGet ( string  path,
timeout  timeout = 60s,
*reference  statinfo 
)

opens a channel for retrieving a remote file with an optional timeout value and an optional reference for returning file status information

an SSH2Channel object is returned to use to retrieve the file's data

Parameters
paththe path of the remote file to get
timeoutan integer giving a timeout in milliseconds or a relative date/time value (ex: 15s for 15 seconds)
statinfoan optional reference to a hash for file status info with the following keys:
  • "mode": the file's mode
  • "permissions": a string of the file's mode (ex: "drwxr-xr-x")
  • "size": the size of the file in bytes
  • "atime": the last access time of the file
  • "mtime": the last modified time of the file
Exceptions
SSH2CLIENT-NOT-CONNECTEDclient is not connected
SSH2CLIENT-TIMEOUTtimeout opening channel
SSH2-ERRORerror opening channel
Example:
my hash $info;
my SS2Channel $chan = $ssh2client.scpGet("/tmp/file.txt", 30s, \$info);
SSH2Channel Qore::SSH2::SSH2Client::scpPut ( string  remote_path,
softint  size,
softint  mode = 0644,
*date  mtime,
*date  atime,
timeout  timeout = 60s 
)

Opens a channel for sending a file to the remote server; an SSH2Channel object is returned to use to send the file's data.

Parameters
remote_paththe path of the file to save on the remote server
sizethe size of the file to send; this parameter is required
modethe file's mode on the remote machine
mtimethe file's last modified time to create on the remote machine
atimethe file's last access time to create on the remote machine
timeoutan integer giving a timeout in milliseconds or a relative date/time value (ex: 15s for 15 seconds)
Exceptions
SSH2CLIENT-NOT-CONNECTEDclient is not connected
SSH2CLIENT-TIMEOUTtimeout opening channel
SSH2-ERRORerror opening channel
Example:
my SS2Channel $chan = $ssh2client.scpPut("/tmp/file.txt", $size, 0644, 2010-12-25, 2010-12-25, 30s);

The documentation for this class was generated from the following file: