Sample code for 30+ languages & platforms
Visual Basic 6.0

Set a TTY Mode for an SSH PTY Request

See more SSH Examples

Demonstrates the Chilkat Ssh.SetTtyMode method, which adds or updates one TTY mode to be included in a later SendReqPty request. The first argument is the mode name and the second is its integer value. Call it once per mode, before requesting the PTY.

Background: TTY modes are the terminal settings a PTY is created with — the same knobs stty exposes. The classic use is SetTtyMode("ECHO", 0), which stops the terminal from echoing input; that is how a password prompt keeps typed characters off the screen. Modes accumulate on the object and are sent with the next PTY request.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Demonstrates the Ssh.SetTtyMode method, which adds or updates one TTY mode to be included in
'  a later SendReqPty request.  The 1st argument is the mode name and the 2nd is its integer
'  value.  Call it once per mode, before SendReqPty.

Dim ssh As New ChilkatSsh

Dim sshPort As Long
sshPort = 22
success = ssh.Connect("ssh.example.com",sshPort)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

'  Normally you would not hard-code the password in source.  You should instead obtain it
'  from an interactive prompt, environment variable, or a secrets vault.
Dim password As String
password = "mySshPassword"

success = ssh.AuthenticatePw("mySshLogin",password)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

'  Open a session channel.  A negative return value indicates failure.
Dim channelNum As Long
channelNum = ssh.OpenSessionChannel()
If (channelNum < 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

'  Request that the allocated terminal not echo input.
success = ssh.SetTtyMode("ECHO",0)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

'  The modes set above are included in the PTY request.
success = ssh.SendReqPty(channelNum,"xterm",80,24,0,0)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

success = ssh.SendReqShell(channelNum)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

ssh.Disconnect