ChilkatSsh ActiveX Reference

ChilkatSsh

A client-side SSH2 implementation for executing commands and shell sessions on Unix/Windows SSH servers.

Object Creation

(Visual Basic 6.0)
Dim obj As New ChilkatSsh
(ASP)
set obj = Server.CreateObject("Chilkat.Ssh")
(VBScript)
set obj = CreateObject("Chilkat.Ssh")
(Delphi)
obj := TChilkatSsh.Create(Self);
(FoxPro)
loObject = CreateObject('Chilkat.Ssh')
(SQL Server)
EXEC @hr = sp_OACreate 'Chilkat.Ssh', @obj OUT
(Javascript)
var obj = new ActiveXObject("Chilkat.Ssh");

Properties

ChannelOpenFailCode As Long (read-only)

If a request to open a channel fails, this property contains a code that identifies the reason for failure. The reason codes are defined in RFC 4254 and are reproduced here:

             Symbolic name                           reason code
             -------------                           -----------
            SSH_OPEN_ADMINISTRATIVELY_PROHIBITED          1
            SSH_OPEN_CONNECT_FAILED                       2
            SSH_OPEN_UNKNOWN_CHANNEL_TYPE                 3
            SSH_OPEN_RESOURCE_SHORTAGE                    4

ChannelOpenFailReason As String (read-only)

The descriptive text corresponding to the ChannelOpenFailCode property.

ClientIdentifier As String

The client-identifier string to be used when connecting to an SSH/SFTP server. Defaults to "SSH-2.0-PuTTY_Local:_Jun_27_2008_16:28:58". (This string is used to mimic PuTTY because some servers are known to disconnect from clients with unknown client identifiers.)

ConnectTimeoutMs As Long

Maximum number of milliseconds to wait when connecting to an SSH server.

DisconnectCode As Long (read-only)

If the SSH server sent a DISCONNECT message when closing the connection, this property contains the "reason code" as specified in RFC 4253:

           Symbolic name                                reason code
           -------------                                -----------
      SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT             1
      SSH_DISCONNECT_PROTOCOL_ERROR                          2
      SSH_DISCONNECT_KEY_EXCHANGE_FAILED                     3
      SSH_DISCONNECT_RESERVED                                4
      SSH_DISCONNECT_MAC_ERROR                               5
      SSH_DISCONNECT_COMPRESSION_ERROR                       6
      SSH_DISCONNECT_SERVICE_NOT_AVAILABLE                   7
      SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED          8
      SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE                 9
      SSH_DISCONNECT_CONNECTION_LOST                        10
      SSH_DISCONNECT_BY_APPLICATION                         11
      SSH_DISCONNECT_TOO_MANY_CONNECTIONS                   12
      SSH_DISCONNECT_AUTH_CANCELLED_BY_USER                 13
      SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE         14
      SSH_DISCONNECT_ILLEGAL_USER_NAME                      15

DisconnectReason As String (read-only)

If the SSH/ server sent a DISCONNECT message when closing the connection, this property contains a descriptive string for the "reason code" as specified in RFC 4253.

HeartbeatMs As Long

This is the number of milliseconds between each AbortCheck event callback. The AbortCheck callback allows an application to abort any SSH operation prior to completion. If HeartbeatMs is 0 (the default), no AbortCheck event callbacks will fire.

HostKeyFingerprint As String (read-only)

Set after connecting to an SSH server. The format of the fingerprint looks like this: "ssh-rsa 1024 68:ff:d1:4e:6c:ff:d7:b0:d6:58:73:85:07:bc:2e:d5"

HttpProxyAuthMethod As String

If an HTTP proxy requiring authentication is to be used, set this property to the HTTP proxy authentication method name. Valid choices are "LOGIN" or "NTLM".

HttpProxyHostname As String

If an HTTP proxy is to be used, set this property to the HTTP proxy hostname or IPv4 address (in dotted decimal notation).

HttpProxyPassword As String

If an HTTP proxy requiring authentication is to be used, set this property to the HTTP proxy password.

HttpProxyPort As Long

If an HTTP proxy is to be used, set this property to the HTTP proxy port number. (Two commonly used HTTP proxy ports are 8080 and 3128.)

HttpProxyUsername As String

If an HTTP proxy requiring authentication is to be used, set this property to the HTTP proxy login name.

IdleTimeoutMs As Long

Causes SSH operations to fail when progress for sending or receiving data halts for more than this number of milliseconds. Setting IdleTimeoutMs = 0 (the default) allows the application to wait indefinitely.

IsConnected As Long (read-only)

Returns 1 if the component is connected to an SSH server.

Note: The IsConnected property is set to 1 after successfully completing the Connect method call. The IsConnected property will only be set to 0 by calling Disconnect, or by the failure of another method call such that the disconnection is detected.

KeepSessionLog As Long

Controls whether communications to/from the SSH server are saved to the SessionLog property. The default value is 0. If this property is set to 1, the contents of the SessionLog property will continuously grow as SSH activity transpires. The purpose of the KeepSessionLog / SessionLog properties is to help in debugging any future problems that may arise.

LastErrorHtml As String (read-only)

Error information in HTML format for the last method called.

LastErrorText As String (read-only)

Error information in plain-text format for the last method called.

LastErrorXml As String (read-only)

Error information in XML format for the last method called.

MaxPacketSize As Long

The maximum packet length to be used in the SSH transport protocol. The default value is 8192. (This should generally be left unchanged.)

NumOpenChannels As Long (read-only)

The number of currently open channels.

ReadTimeoutMs As Long

The maximum amount of time to allow for reading messages/data from the SSH server. This is different from the IdleTimeoutMs property. The IdleTimeoutMs is the maximum amount of time to wait while no incoming data is arriving. The ReadTimeoutMs is the maximum amount of time to allow for reading data even if data is continuing to arrive. The default value of 0 indicates an infinite timeout value.

SessionLog As String (read-only)

Contains a log of the messages sent to/from the SSH server. To enable session logging, set the KeepSessionLog property = 1. Note: This property is not a filename -- it is a string property that contains the session log data.

SocksHostname As String

The SOCKS4/SOCKS5 hostname or IPv4 address (in dotted decimal notation). This property is only used if the SocksVersion property is set to 4 or 5).

SocksPassword As String

The SOCKS5 password (if required). The SOCKS4 protocol does not include the use of a password, so this does not apply to SOCKS4.

SocksPort As Long

The SOCKS4/SOCKS5 proxy port. The default value is 1080. This property only applies if a SOCKS proxy is used (if the SocksVersion property is set to 4 or 5).

SocksUsername As String

The SOCKS4/SOCKS5 proxy username. This property is only used if the SocksVersion property is set to 4 or 5).

SocksVersion As Long

SocksVersion May be set to one of the following integer values:

0 - No SOCKS proxy is used. This is the default.
4 - Connect via a SOCKS4 proxy.
5 - Connect via a SOCKS5 proxy.

TcpNoDelay As Long

Controls whether the TCP_NODELAY socket option is used for the underlying TCP/IP socket. The default value is 1. This disables the Nagle algorithm and allows for better performance when small amounts of data are sent to/from the SSH server.

VerboseLogging As Long

To be documented soon...

Version As String (read-only)

A version string such as "2.1.0". This indicates the version of the Chilkat component.

Methods

AuthenticatePk(username As String, privateKey As ChilkatSshKey) As Long

Authenticates with the SSH server using public-key authentication. The corresponding public key must have been installed on the SSH server for the username. Authentication will succeed if the matching privateKey is provided.

Important: When reporting problems, please send the full contents of the LastErrorText property to support@chilkatsoft.com.

Returns 1 for success, 0 for failure.

AuthenticatePw(login As String, password As String) As Long

Authenticates with the SSH server using a login and password.

An SSH session always begins by first calling Connect to connect to the SSH server, and then calling either AuthenticatePw or AuthenticatePk to login.

Important: When reporting problems, please send the full contents of the LastErrorText property to support@chilkatsoft.com.

Returns 1 for success, 0 for failure.

ChannelIsOpen(channelNum As Long) As Long

Returns 1 if the channel indicated by channelNum is open. Otherwise returns 0.

ChannelPoll(channelNum As Long, pollTimeoutMs As Long) As Long

Polls for incoming data on an open channel. This method will read a channel, waiting at most pollTimeoutMs milliseconds for data to arrive. Return values are as follows:

-1 -- Error. Check the IsConnected property to see if the connection to the SSH server is still valid. Also, call ChannelIsOpen to see if the channel remains open. The LastErrorText property will contain more detailed information regarding the error.

-2 -- No additional data was received prior to the poll timeout.

>0 -- Additional data was received and the return value indicates how many bytes are available to be "picked up". Methods that read data on a channel do not return the received data directly. Instead, they return an integer to indicate how many bytes are available to be "picked up". An application picks up the available data by calling GetReceivedData or GetReceivedText.

ChannelRead(channelNum As Long) As Long

Reads incoming data on an open channel. This method will read a channel, waiting at most IdleTimeoutMs milliseconds for data to arrive. Return values are as follows:

-1 -- Error. Check the IsConnected property to see if the connection to the SSH server is still valid. Also, call ChannelIsOpen to see if the channel remains open. The LastErrorText property will contain more detailed information regarding the error.

-2 -- No additional data was received prior to the IdleTimeoutMs timeout.

>0 -- Additional data was received and the return value indicates how many bytes are available to be "picked up". Methods that read data on a channel do not return the received data directly. Instead, they return an integer to indicate how many bytes are available to be "picked up". An application picks up the available data by calling GetReceivedData or GetReceivedText.

ChannelReadAndPoll(channelNum As Long, pollTimeoutMs As Long) As Long

Reads incoming data on an open channel and continues reading until no data arrives for pollTimeoutMs milliseconds. The first read will wait a max of IdleTimeoutMs milliseconds before timing out. Subsequent reads wait a max of pollTimeoutMs milliseconds before timing out.

The idea behind ChannelReadAndPoll is to capture the output of a shell command. One might imagine the typical sequence of events when executing a shell command to be like this: (1) client sends command to server, (2) server executes the command (i.e. it's computing...), potentially taking some amount of time, (3) output is streamed back to the client. It makes sense for the client to wait a longer period of time for the first data to arrive, but once it begins arriving, the timeout can be shortened. This is exactly what ChannelReadAndPoll does -- the first timeout is controlled by the IdleTimeoutMs property, while the subsequent reads (once output starts flowing) is controlled by pollTimeoutMs.

Return values are as follows:
-1 -- Error. Check the IsConnected property to see if the connection to the SSH server is still valid. Also, call ChannelIsOpen to see if the channel remains open. The LastErrorText property will contain more detailed information regarding the error.

-2 -- No additional data was received prior to the IdleTimeoutMs timeout.

>0 -- Additional data was received and the return value indicates how many bytes are available to be "picked up". Methods that read data on a channel do not return the received data directly. Instead, they return an integer to indicate how many bytes are available to be "picked up". An application picks up the available data by calling GetReceivedData or GetReceivedText.

ChannelReadAndPoll2(channelNum As Long, pollTimeoutMs As Long, maxNumBytes As Long) As Long

The same as ChannelReadAndPoll, except this method will return as soon as maxNumBytes is exceeded, which may be as large as the MaxPacketSize property setting.

ChannelReceiveToClose(channelNum As Long) As Long

Reads incoming data on an open channel until the channel is closed by the server. If successful, the number of bytes available to be "picked up" can be determined by calling GetReceivedNumBytes. The received data may be retrieved by calling GetReceivedData or GetReceivedText.

Returns 1 for success, 0 for failure.

ChannelReceiveUntilMatch(channelNum As Long, matchPattern As String, charset As String, caseSensitive As Long) As Long

Reads incoming text data on an open channel until the received data matches the matchPattern. For example, to receive data until the string "Hello World" arrives, set matchPattern equal to "*Hello World*". charset indicates the character encoding of the text being received ("iso-8859-1" for example). caseSensitive may be set to 1 for case sensitive matching, or 0 for case insensitive matching.

Returns 1 if text data matching matchPattern was received and is available to be picked up by calling GetReceivedText (or GetReceivedTextS). IMPORTANT: This method may read beyond the matching text. Call GetReceivedTextS to extract only the data up-to and including the matching text.

Returns 1 for success, 0 for failure.

ChannelReceiveUntilMatchN(channelNum As Long, matchPatterns As CkStringArray, charset As String, caseSensitive As Long) As Long

To be documented soon...

ChannelReceivedClose(channelNum As Long) As Long

1 if a CLOSE message has been received on the channel indicated by channelNum. When a CLOSE is received, no subsequent data should be sent in either direction -- the channel is closed in both directions.

ChannelReceivedEof(channelNum As Long) As Long

1 if an EOF message has been received on the channel indicated by channelNum. When an EOF is received, no more data will be forthcoming on the channel. However, data may still be sent in the opposite direction.

ChannelReceivedExitStatus(channelNum As Long) As Long

1 if an exit status code was received on the channel. Otherwise 0.

ChannelSendClose(channelNum As Long) As Long

Sends a CLOSE message to the server for the channel indicated by channelNum. This closes both directions of the bidirectional channel.

Returns 1 for success, 0 for failure.

ChannelSendData(channelNum As Long, byteData As Variant) As Long

Sends byte data on the channel indicated by channelNum.

Returns 1 for success, 0 for failure.

ChannelSendEof(channelNum As Long) As Long

Sends an EOF for the channel indicated by channelNum. Once an EOF is sent, no additional data may be sent on the channel. However, the channel remains open and additional data may still be received from the server.

Returns 1 for success, 0 for failure.

ChannelSendString(channelNum As Long, textData As String, charset As String) As Long

Sends character data on the channel indicated by channelNum. The text is converted to the charset indicated by charset prior to being sent. A list of supported charset values may be found on this page: Supported Charsets.

Returns 1 for success, 0 for failure.

ClearTtyModes()

To be documented soon.

Connect(hostname As String, port As Long) As Long

Connects to the SSH server at hostname: port

Returns 1 for success, 0 for failure.

Disconnect()

Disconnects from the SSH server.

GetChannelExitStatus(channelNum As Long) As Long

Returns the exit status code for a channel. This method should only be called if an exit status has been received. You may check to see if the exit status was received by calling ChannelReceivedExitStatus.

GetChannelNumber(index As Long) As Long

Returns the channel number for the Nth open channel. Indexing begins at 0, and the number of currently open channels is indicated by the NumOpenChannels property. Returns -1 if the index is out of range.

GetChannelType(index As Long) As String

Returns a string describing the channel type for the Nth open channel. Channel types are: "session", "x11", "forwarded-tcpip", and "direct-tcpip".

Returns a null on failure

GetReceivedData(channelNum As Long) As Variant

Returns the accumulated data received on the channel indicated by channelNum and clears the channel's internal receive buffer.

Returns a zero-length byte array (as a Variant) on failure

GetReceivedDataN(channelNum As Long, maxNumBytes As Long) As Variant

Same as GetReceivedData, but a maximum of maxNumBytes bytes is returned.

Returns a zero-length byte array (as a Variant) on failure

GetReceivedNumBytes(channelNum As Long) As Long

Returns the number of bytes available in the internal receive buffer for the specified channelNum. The received data may be retrieved by calling GetReceivedData or GetReceivedText.

GetReceivedStderr(channelNum As Long) As Variant

To be documented soon.

Returns a zero-length byte array (as a Variant) on failure

GetReceivedText(channelNum As Long, charset As String) As String

Returns the accumulated text received on the channel indicated by channelNum and clears the channel's internal receive buffer. The charset indicates the charset of the character data in the internal receive buffer. A list of supported charset values may be found on this page: Supported Charsets.

Returns a null on failure

GetReceivedTextS(channelNum As Long, substr As String, charset As String) As String

The same as GetReceivedText, except only the text up to and including substr is returned. The text returned is removed from the internal receive buffer. If the substr was not found in the internal receive buffer, an empty string is returned and the internal receive buffer is not modified.

Returns a null on failure

OpenCustomChannel(channelType As String) As Long

Opens a custom channel with a custom server that uses the SSH protocol. The channelType is application-defined.

If successful, the channel number is returned. This is the number that should be passed to any method requiring a channel number. A -1 is returned upon failure.

OpenDirectTcpIpChannel(targetHostname As String, targetPort As Long) As Long

Open a direct-tcpip channel for port forwarding. Data sent on the channel via ChannelSend* methods is sent to the SSH server and then forwarded to targetHostname: targetPort. The SSH server automatically forwards data received from targetHostname: targetPort to the SSH client. Therefore, calling ChannelRead* and ChannelReceive* methods is equivalent to reading directly from targetHostname: targetPort.

If successful, the channel number is returned. This is the number that should be passed to any method requiring a channel number. A -1 is returned upon failure.

(ASP) SSH Tunnel (Port Forwarding via direct-tcpip channel)

(VB6) SSH Tunnel (Port Forwarding via direct-tcpip channel)

(Delphi) SSH Tunnel (Port Forwarding via direct-tcpip channel)

(FoxPro) SSH Tunnel (Port Forwarding via direct-tcpip channel)

(VBScript) SSH Tunnel (Port Forwarding via direct-tcpip channel)

OpenSessionChannel() As Long

Opens a new session channel. Almost everything you will do with the Chilkat SSH component will involve opening a session channel. The normal sequence of operation is typically this: 1) Connect to the SSH server. 2) Authenticate. 3) Open a session channel. 4) do something on the channel such as opening a shell, execute a command, etc.

If successful, the channel number is returned. This is the number that should be passed to any method requiring a channel number. A -1 is returned upon failure.

PeekReceivedText(channelNum As Long, charset As String) As String

This is the same as GetReceivedText, except the internal receive buffer is not cleared.

Returns a null on failure

ReKey() As Long

Initiates a re-key with the SSH server. The ReKey method does not return until the key re-exchange is complete.

RFC 4253 (the SSH Transport Layer Protocol) recommends that keys be changed after each gigabyte of transmitted data or after each hour of connection time, whichever comes sooner. Key re-exchange is a public-key operation and requires a fair amount of processing power and should not be performed too often. Either side (client or server) may initiate a key re-exchange at any time.

In most cases, a server will automatically initiate key re-exchange whenever it deems necessary, and the Chilkat SSH component handles these transparently. For example, if the Chilkat SSH component receives a re-key message from the server while in the process of receiving data on a channel, it will automatically handle the key re-exchange and the application will not even realize that an underlying key re-exchange occurred.

Returns 1 for success, 0 for failure.

SaveLastError(logFilename As String) As Long

Saves the last error information to an XML formatted file.

SendIgnore() As Long

Sends an IGNORE message to the SSH server. This is one way of verifying that the connection to the SSH server is open and valid. The SSH server does not response it an IGNORE message, it simply ignores it. IGNORE messages are not associated with a channel (in other words, you do not need to first open a channel prior to sending an IGNORE message).

Returns 1 for success, 0 for failure.

SendReqExec(channelNum As Long, commandLine As String) As Long

Initiates execution of a command on the channel specified by channelNum. The commandLine contains the full command line including any command-line parameters (just as you would type the command at a shell prompt).

The user's default shell (typically defined in /etc/password in UNIX systems) is started on the SSH server to execute the command.

Important: A channel only exists for a single request. You may not call SendReqExec multiple times on the same open channel. The reason is that the SSH server automatically closes the channel at the end of the exec. The solution is to call OpenSessionChannel to get a new channel, and then call SendReqExec using the new channel. It is OK to have more than one channel open simultaneously.

Returns 1 for success, 0 for failure.

(ASP) SSH Exec (Execute Command Line)

(VB6) SSH Exec (Execute Command Line)

(Delphi) SSH Exec (Execute Command Line)

(FoxPro) SSH Exec (Execute Command Line)

(VBScript) SSH Exec (Execute Command Line)

(ASP) Multiple SendReqExec on Same Connection

(VB6) Multiple SendReqExec on Same Connection

(Delphi) Multiple SendReqExec on Same Connection

(FoxPro) Multiple SendReqExec on Same Connection

(VBScript) Multiple SendReqExec on Same Connection

SendReqPty(channelNum As Long, termType As String, widthInChars As Long, heightInChars As Long, widthInPixels As Long, heightInPixels As Long) As Long

Requests a pseudo-terminal for a session channel. If the termType is a character oriented terminal ("vt100" for example), then widthInChars and heightInChars would be set to non-zero values, while widthInPixels and heightInPixels may be set to 0. If termType is pixel-oriented, such as "xterm", the reverse is true (i.e. set widthInPixels and heightInPixels, but set widthInChars and heightInChars equal to 0).

In most cases, you probably don't even want terminal emulation. In that case, try setting termType = "dumb". Terminal emulation causes terminal escape sequences to be included with shell command output. A "dumb" terminal should have no escape sequences.

Some SSH servers allow a shell to be started (via the SendReqShell method) without the need to first request a pseudo-terminal. The normal sequence for starting a remote shell is as follows:

1) Connect
2) Authenticate
3) OpenSessionChannel
4) Request a PTY via this method if necessary.
5) Start a shell by calling SendReqShell

Returns 1 for success, 0 for failure.

SendReqSetEnv(channelNum As Long, name As String, value As String) As Long

Sets an environment variable in the remote shell.

Returns 1 for success, 0 for failure.

SendReqShell(channelNum As Long) As Long

Starts a shell on an open session channel. Some SSH servers require that a PTY (pseudo-terminal) first be requested prior to starting a shell. In that case, call SendReqPty prior to calling this method. Once a shell is started, commands may be sent by calling ChannelSendString. (Don't forget to terminate commands with a CRLF).

Returns 1 for success, 0 for failure.

(ASP) SSH Remote Shell

(VB6) SSH Remote Shell

(Delphi) SSH Remote Shell

(FoxPro) SSH Remote Shell

(VBScript) SSH Remote Shell

(ASP) SSH -- Running Commands that Prompt for Additional Input, such as "su"

(VB6) SSH -- Running Commands that Prompt for Additional Input, such as "su"

(Delphi) SSH -- Running Commands that Prompt for Additional Input, such as "su"

(FoxPro) SSH -- Running Commands that Prompt for Additional Input, such as "su"

(VBScript) SSH -- Running Commands that Prompt for Additional Input, such as "su"

SendReqSignal(channelNum As Long, signalName As String) As Long

Delivers a signal to the remote process/service. signalName is one of the following: ABRT, ALRM, FPE, HUP, ILL, INT, KILL, PIPE, QUIT, SEGV, TERM, USR1, USR2. (Obviously, these are UNIX signals, so the remote SSH server would need to be a Unix/Linux system.)

Returns 1 for success, 0 for failure.

SendReqSubsystem(channelNum As Long, subsystemName As String) As Long

Executes a pre-defined subsystem. The SFTP protocol (Secure File Transfer Protocol) is started by the Chilkat SFTP component by starting the "sftp" subsystem.

Returns 1 for success, 0 for failure.

SendReqWindowChange(channelNum As Long, widthInChars As Long, heightInRows As Long, pixWidth As Long, pixHeight As Long) As Long

To be documented soon...

SendReqX11Forwarding(channelNum As Long, singleConnection As Long, authProt As String, authCookie As String, screenNum As Long) As Long

To be documented soon...

SendReqXonXoff(channelNum As Long, clientCanDo As Long) As Long

To be documented soon...

SetTtyMode(name As String, value As Long) As Long

To be documented soon...

UnlockComponent(unlockCode As String) As Long

Unlocks the component. This must be called once prior to calling any other method. A fully-functional 30-day trial is automatically started when an arbitrary string is passed to this method. For example, passing "Hello", or "abc123" will unlock the component for the 1st thirty days after the initial install.

Returns 1 for success, 0 for failure.