Platforms to show: All Mac Windows Linux Cross-Platform

Back to SSH2SessionMBS class.

SSH2SessionMBS.Banner as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Get the remote banner.

Once the session has been setup and Handshake has completed successfully, this function can be used to get the server id from the banner each server presents.

SSH2SessionMBS.ConfigureKeepAlive(WantReply as Boolean = true, Interval as Integer = 2)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 20.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Configures keep alive probes.

Set how often keepalive messages should be sent.
WantReply indicates whether the keepalive messages should request a response from the server.
Interval is number of seconds that can pass without any I/O, use 0 to disable keepalives. To avoid some busy-loop corner-cases, if you specify an interval of 1 it will be treated as 2.

Some examples using this method:

SSH2SessionMBS.Constructor(IP as string, Port as Integer = 22, TimeOut as Integer = 30)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The constructor for using a new socket.

The plugin creates a new socket, connects to the given IP&Port and than creates a new session for it.
Lasterror is set.
Please check if Handle property is non zero after constructor finishes.

Timeout defines timeout for connection in seconds. While waiting, the plugin yields time to other threads.
If timeout is zero, the connection will not yield and take up to the default TCP/IP timeout.

IPv4, IPv6 address or domain name with version 18.3 or newer.

See also:

SSH2SessionMBS.Constructor(socket as TCPSocket)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The constructor for using an existing socket.

Initializes a new session.
socket: The socket to use. The plugin keeps reference to this socket in socket property.

You can use a Xojo socket and connect it. Once connected, pass it here, so the session can use this socket for communication.
If you connect the xojo socket in a loop on a thread, be sure to call poll method of socket, so it processes events like connecting. In main thread with timer, you would get this automatically.

See also:

SSH2SessionMBS.Constructor(socketHandle as Integer, CloseSocketLater as boolean = false)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The constructor for using an existing socket.

Initializes a new session.
socketHandle: The socket to use. Can be TCPSocket's handle property for a Xojo socket. Or a socket connected via declares.
You can put the socket in the socket property to keep it alive as long as session is in memory.

Set CloseSocketLater = true if you pass a socket which can be closed in destructor. For Xojo socket, pass false as Xojo closes socket later.
You can use a Xojo socket and connect it. Once connected, pass it here, so the session can use this socket for communication.

See also:

SSH2SessionMBS.Destructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The destructor.

SSH2SessionMBS.Disconnect(description as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Terminate transport layer.

Lasterror is set.
description: Human readable reason for disconnection.

See also:

SSH2SessionMBS.Disconnect(reason as Integer, description as string, lang as string = "")

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Terminate transport layer.

Lasterror is set.

reason: One of the Disconnect Reason constants.
description: Human readable reason for disconnection.
lang: Localization string describing the langauge/encoding of the description provided.

See also:

SSH2SessionMBS.HostKeyHash(HashType as Integer) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Return a hash of the remote host's key.

HashType: kHostKeyHashSHA1 or kHostKeyHashMD5.
Returns the computed digest of the remote system's hostkey. The length of the returned string is hash_type specific (e.g. 16 bytes for MD5, 20 bytes for SHA1).
Computed hostkey hash value, or empty string if the information is not available (either the session has not yet been started up, or the requested hash algorithm was not available). The hash consists of raw binary bytes, not hex digits, so it is not directly printable.

Some examples using this method:

SSH2SessionMBS.OpenDirectTCPIPChannel(host as string, port as integer, sourceHost as string = "127.0.0.1", sourcePort as Integer = 22) as SSH2ChannelMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 18.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Tunnel a TCP connection through an SSH session.

host: Third party host to connect to using the SSH host as a proxy.
port: Port on third party host to connect to.
SourceHost: Host to tell the SSH server the connection originated on.
SourcePort: Port to tell the SSH server the connection originated from.

Tunnel a TCP/IP connection through the SSH transport via the remote host to a third party. Communication from the client to the SSH server remains encrypted, communication from the server to the 3rd party host travels in cleartext.

This is not a replacement for ssh in command line with -L option.

Returns a newly allocated channel object, or nil on errors.

Some examples using this method:

SSH2SessionMBS.OpenSession as SSH2ChannelMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Establish a generic session channel.

Lasterror is set.
Returns nil if the session start fails.

SSH2SessionMBS.SessionFlag(Flag as Integer, Value as boolean)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Get/Set a session flag.

See kFlag* constants.
Lasterror is set.

SSH2SessionMBS.SetBanner(Banner as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Set the SSH prococol banner for the local client.

Set the banner that will be sent to the remote host when the SSH session is started with Handshake. This is optional; a banner corresponding to the protocol and libssh2 version will be sent by default.
Lasterror is set.

SSH2SessionMBS.SetMethodPreference(methodType as Integer, Pref as string) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 18.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Set preferred key exchange method.
Example
// set preferences for key exchange method:
dim r as Boolean = s.SetMethodPreference(SSH2SessionMBS.kMethodKEX, "diffie-hellman-group-exchange-sha256")

methodType: One of the Method Type constants.
Pref: Coma delimited list of preferred methods to use with the most preferred listed first and the least preferred listed last. If a method is listed which is not supported by libssh2 it will be ignored and not sent to the remote host during protocol negotiation.

Set preferred methods to be negotiated. These preferences must be set prior to calling SessionHandshake, as they are used during the protocol initiation phase.

Return true on success or false on failure. Lasterror is set. Lasterror is set to LIBSSH2_ERROR_EAGAIN (-37) when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se.

SSH2SessionMBS.SupportedAlgorithms(methodType as Integer) as String()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 18.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Get list of supported algorithms.
Example
dim s as new SSH2SessionMBS("localhost")

dim KeyExchange() as string = s.SupportedAlgorithms(SSH2SessionMBS.kMethodKEX)
dim HostKey() as string = s.SupportedAlgorithms(SSH2SessionMBS.kMethodHostKey)
dim CryptCS() as string = s.SupportedAlgorithms(SSH2SessionMBS.kMethodCryptCS)
dim CryptSC() as string = s.SupportedAlgorithms(SSH2SessionMBS.kMethodCryptSC)
dim MacCS() as string = s.SupportedAlgorithms(SSH2SessionMBS.kMethodMacCS)
dim MacSC() as string = s.SupportedAlgorithms(SSH2SessionMBS.kMethodMacSC)
dim CompCS() as string = s.SupportedAlgorithms(SSH2SessionMBS.kMethodCompCS)
dim CompSC() as string = s.SupportedAlgorithms(SSH2SessionMBS.kMethodCompSC)
dim LangCS() as string = s.SupportedAlgorithms(SSH2SessionMBS.kMethodLangCS)
dim LangSC() as string = s.SupportedAlgorithms(SSH2SessionMBS.kMethodLangSC)

Break

Method type: see kMethod* constants.

Get a list of supported algorithms for the given methodType. The methodType parameter is equivalent to methodType in SetMethodPreference.

In order to get a list of all supported compression algorithms, SessionFlag(SSH2SessionMBS.kFlagCompress, true) must be called before calling this function, otherwise only "none" will be returned.

On success, returns array with algorithms
Lasterror is set with error code.

SSH2SessionMBS.UserAuthKeyboardInteractive(UserName as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Authenticate a session using keyboard-interactive authentication.

username: Name of user to attempt keyboard-interactive authentication for.
Lasterror is set.
Calls KeyboardCallback callback to query input from user.

Some examples using this method:

SSH2SessionMBS.UserAuthList(username as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
List supported authentication methods.

username: Username which will be used while authenticating. Note that most server implementations do not permit attempting authentication with different usernames between requests. Therefore this must be the same username you will use on later userauth calls.

Send a SSH_USERAUTH_NONE request to the remote host. Unless the remote host is configured to accept none as a viable authentication scheme (unlikely), it will return SSH_USERAUTH_FAILURE along with a listing of what authentication schemes it does support. In the unlikely event that none authentication succeeds, this method with return NULL. This case may be distinguished from a failing case by examining Authenticated.

Some examples using this method:

SSH2SessionMBS.UserAuthPassword(UserName as string, Password as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Authenticate a session with username and password.

username: Name of user to attempt plain password authentication for.
password: Password to use for authenticating username.

Attempt basic password authentication. Note that many SSH servers which appear to support ordinary password authentication actually have it disabled and use Keyboard Interactive authentication (routed via PAM or another authentication backed) instead.
Lasterror is set.

Some examples using this method:

SSH2SessionMBS.UserAuthPublicKeyFromFile(UserName as string, publickey as folderitem, privatekey as folderitem, Passphrase as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Authenticate a session with a public key, read from a file.

Lasterror is set.
username: user name to authenticate as.
publickey: Path of the public key file. (e.g. /etc/ssh/hostkey.pub). If libssh2 is built against OpenSSL, this option can be set to ""/nil.
privatekey: Path of the private key file. (e.g. /etc/ssh/hostkey)
passphrase: Passphrase to use when decoding privatekey.

Attempt public key authentication using a PEM encoded private key file stored on disk

See also:

Some examples using this method:

SSH2SessionMBS.UserAuthPublicKeyFromFile(UserName as string, publickey as string, privatekey as string, Passphrase as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Authenticate a session with a public key, read from a file.

Lasterror is set.
username: user name to authenticate as.
publickey: Path of the public key file. (e.g. /etc/ssh/hostkey.pub). If libssh2 is built against OpenSSL, this option can be set to ""/nil.
privatekey: Path of the private key file. (e.g. /etc/ssh/hostkey)
passphrase: Passphrase to use when decoding privatekey.

Attempt public key authentication using a PEM encoded private key file stored on disk

See also:

SSH2SessionMBS.UserAuthPublicKeyFromMemory(UserName as string, publickey as string, privatekey as string, Passphrase as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 16.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Authenticate a session with a public key, read from memory

This function allows to authenticate a session with a public key read from memory.
Lasterror is set.

username - Remote user name to authenticate as.
publickeydata - Buffer containing the contents of a public key file. Optional.
privatekeydata - Buffer containing the contents of a private key file.
passphrase - Passphrase to use when decoding private key file.

Keys must have LF as line ending, not CR.

Attempt public key authentication using a PEM encoded private key file stored in memory.

SSH2SessionMBS.WaitSocket(TimeOut as Double = 0.1)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Network MBS Network Plugin 14.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Waits on the socket for sending or receiving.

Default used to be 10 seconds, but that may be to much, so since v22.3 the value can be customized and is now 1/10th of a second.

Some examples using this method:

The items on this page are in the following plugins: MBS Network Plugin.


The biggest plugin in space...