Sample code for 30+ languages & platforms
PureBasic

Authenticate an SSH Tunnel with a Password

See more Socket/SSL/TLS Examples

Demonstrates Socket.SshAuthenticatePw, which authenticates an SSH tunnel session using a login and password. Call SshOpenTunnel first.

Background. Authenticate before opening forwarded channels. The password should come from a secure source and never be logged; public-key authentication is often preferred.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkSocket.pb"

Procedure ChilkatExample()

    success.i = 0

    socket.i = CkSocket::ckCreate()
    If socket.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkSocket::ckSshOpenTunnel(socket,"ssh.example.com",22)
    If success = 0
        Debug CkSocket::ckLastErrorText(socket)
        CkSocket::ckDispose(socket)
        ProcedureReturn
    EndIf

    ;  Authenticate the SSH tunnel session with a login and password.
    ;  The SSH password should come from a secure source rather than being hard-coded.
    sshPassword.s = "mySshPassword"
    success = CkSocket::ckSshAuthenticatePw(socket,"sshUser",sshPassword)
    If success = 0
        Debug CkSocket::ckLastErrorText(socket)
        CkSocket::ckDispose(socket)
        ProcedureReturn
    EndIf

    Debug "SSH authentication succeeded."


    CkSocket::ckDispose(socket)


    ProcedureReturn
EndProcedure