PureBasic
PureBasic
Connect to an SSH Server
See more SSH Examples
Demonstrates the Chilkat Ssh.Connect method, which establishes a connection to an SSH server. The first argument is the hostname (a DNS name or a numeric IPv4/IPv6 address) and the second is the TCP port, usually 22. Connecting is the first step; authentication follows before any channels can be opened.
Background:
Connect establishes only the SSH transport — the encrypted channel and host-key exchange — but does not log in. An SSH session is always used in stages: connect, authenticate, then open one or more channels for shell, exec, or port-forwarding work. Timeouts and optional SOCKS/HTTP proxying are controlled by the object's properties before this call.Chilkat PureBasic Downloads
IncludeFile "CkSsh.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the Ssh.Connect method, which establishes a connection to an SSH server. The
; 1st argument is the hostname (a DNS name or numeric IP) and the 2nd is the TCP port.
ssh.i = CkSsh::ckCreate()
If ssh.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Port 22 is the usual SSH port.
sshPort.i = 22
success = CkSsh::ckConnect(ssh,"ssh.example.com",sshPort)
If success = 0
Debug CkSsh::ckLastErrorText(ssh)
CkSsh::ckDispose(ssh)
ProcedureReturn
EndIf
Debug "Connected to the SSH server."
; (Authentication would follow here before opening channels.)
CkSsh::ckDisconnect(ssh)
CkSsh::ckDispose(ssh)
ProcedureReturn
EndProcedure