-
-
Notifications
You must be signed in to change notification settings - Fork 4
SSH.Session
SSH.Session
Protected Class Session
This class represents a SSH session. A session is a TCP connection over which SSH traffic is sent and received. A given session can multiplex any number of Channels over its single TCP connection.
When you create a new instance of Session
it is not connected. You must call Connect()
to open the TCP connection and begin the SSH2 handshake. After the connection is established the user needs to log in. Before sending the user's credentials it is usually wise to compare the remote host's fingerprint to a list of known hosts.
This example creates a new session, connects to the remote server, verifies the server's fingerprint against a list of known hosts, and finally authenticates to the server by sending a username and a password.
Dim session As New SSH.Session()
If Not session.Connect("ssh.example.com", 22) Then
MsgBox("Unable to connect!")
Return
End If
' locate the user's known_hosts file (or supply your own)
Dim f As FolderItem = SpecialFolder.UserHome.Child(".ssh")
If f.Exists Then f = f.Child("known_hosts")
If f.Exists Then
Dim known As New SSH.KnownHosts(session)
Call known.Load(f)
If Not session.CheckHost(known, False) Then
If session.LastError = SSH.ERR_HOSTKEY_NOTFOUND Then
Call MsgBox("Fingerprint not known!", 16, "Unknown server")
Return
ElseIf session.LastError = SSH.ERR_HOSTKEY_MISMATCH Then
Call MsgBox("Fingerprint has changed!", 16, "Security breach")
Return
ElseIf session.LastError <> 0 Then
Call MsgBox("Unable to verify fingerprint.", 16, "Unknown error")
Return
End If
End If
End If
If Not session.SendCredentials("username", "password") Then
MsgBox("Invalid user/pass!")
Return
End If
- BlockInbound
- BlockOutbound
- CheckHost
- Close
- Connect
- Constructor
- GetActualAlgorithm
- GetAuthenticationMethods
- GetAvailableAlgorithms
- GetLastError
- GetRemoteBanner
- HostKeyHash
- KeepAlive
- Poll
- SendCredentials
- SetFlag
- SetLocalBanner
- SetPreferredAlgorithms
- Blocking As Boolean
- Descriptor As Integer
- Handle As Ptr
- HostKey As MemoryBlock
- HostKeyType As Integer
- IsAuthenticated As Boolean
- IsConnected As Boolean
- KeepAlivePeriod As Integer
- LastError As Int32
- LastErrorMsg As String
- NetworkInterface As NetworkInterface
- RemoteHost As String
- RemotePort As Integer
- Timeout As Integer
- UseCompression As Boolean
- Username As String
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2018-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.