Skip to content

SSH.Connect

Andrew Lambert edited this page Nov 26, 2022 · 7 revisions

SSH.Connect

Method signatures

 Protected Function Connect(URL As String, KnownHostList As FolderItem = Nil, AddHost As Boolean = False) As SSH.Session
 Protected Function Connect(Address As String, Port As Integer, Username As String, PublicKeyFile As FolderItem, PrivateKeyFile As FolderItem, PrivateKeyFilePassword As String, KnownHostList As FolderItem = Nil, AddHost As Boolean = False) As SSH.Session
 Protected Function Connect(Address As String, Port As Integer, Username As String, PublicKey As MemoryBlock, PrivateKey As MemoryBlock, PrivateKeyPassword As String, KnownHostList As FolderItem = Nil, AddHost As Boolean = False) As SSH.Session
 Protected Function Connect(Address As String, Port As Integer, Username As String, Password As String, KnownHostList As FolderItem = Nil, AddHost As Boolean = False) As SSH.Session
 Protected Function Connect(Address As String, Port As Integer, Username As String, KnownHostList As FolderItem = Nil, AddHost As Boolean = False) As SSH.Session

Parameters

Connect(String, FolderItem, Boolean)

Connect using the username, password, address, and port specified as a URL. e.g. ssh://user:pass@ssh.example.com:2222.

Name Type Comment
URL String The fully-qualified URL of the server (including username/password).
KnownHostList FolderItem Optional. A list of known hosts to check the server against.
AddHost Boolean Optional. If True, then the server's fingerprint is added to the list if necessary.

Connect(String, Integer, String, FolderItem, FolderItem, String, FolderItem, Boolean)

Connect using keys from a file.

Name Type Comment
Address String The hostname or IP address to connect to.
Port Integer The remote port to connect to.
Username String The user to log in as.
PublicKeyFile FolderItem The user's public key.
PrivateKeyFile FolderItem The user's private key.
PrivateKeyFilePassword String The password needed to unlock the private key.
KnownHostList FolderItem Optional. A list of known hosts to check the server against.
AddHost Boolean Optional. If True, then the server's fingerprint is added to the list if necessary.

Connect(String, Integer, String, MemoryBlock, MemoryBlock, String, FolderItem, Boolean)

Connect using keys from memory.

Name Type Comment
Address String The hostname or IP address to connect to.
Port Integer The remote port to connect to.
Username String The user to log in as.
PublicKey MemoryBlock The user's public key.
PrivateKey MemoryBlock The user's private key.
PrivateKeyPassword String The password needed to unlock the private key.
KnownHostList FolderItem Optional. A list of known hosts to check the server against.
AddHost Boolean Optional. If True, then the server's fingerprint is added to the list if necessary.

Connect(String, Integer, String, String, FolderItem, Boolean)

Connect with a username and password.

Name Type Comment
Address String The hostname or IP address to connect to.
Port Integer The remote port to connect to.
Username String The user to log in as.
Password String The user's password.
KnownHostList FolderItem Optional. A list of known hosts to check the server against.
AddHost Boolean Optional. If True, then the server's fingerprint is added to the list if necessary.

Connect(String, Integer, String, FolderItem, Boolean)

Connect using the local SSH agent.

Name Type Comment
Address String The hostname or IP address to connect to.
Port Integer The remote port to connect to.
Username String The user to log in as (keys to be provided by an SSH agent).
KnownHostList FolderItem Optional. A list of known hosts to check the server against.
AddHost Boolean Optional. If True, then the server's fingerprint is added to the list if necessary.

Return value

An instance of the SSH.Session class.

Remarks

This convenience method establishes an SSH session to the server specified by the parameters.

If the KnownHostsList file is specified then the server's fingerprint is checked against the list. If AddHost is true then the fingerprint will be added to the list if it's not already present. If the server's fingerprint was found in the list but does not match the one presented by the remote host then the connection will fail even if AddHost is True: if, and only if, this change was expected then remove the old fingerprint and try again.

Returns an instance of the Session class even if an error occurred. Check Session.IsConnected and Session.IsAuthenticated to determine whether an error occurred, and Session.LastError for error details.

Clone this wiki locally