AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; 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.
$oSsh = ObjCreate("Chilkat.Ssh")
Local $iSshPort = 22
$bSuccess = $oSsh.Connect("ssh.example.com",$iSshPort)
If ($bSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
; 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.
Local $sPassword = "mySshPassword"
$bSuccess = $oSsh.AuthenticatePw("mySshLogin",$sPassword)
If ($bSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
; Open a session channel. A negative return value indicates failure.
Local $iChannelNum = $oSsh.OpenSessionChannel()
If ($iChannelNum < 0) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
; Request that the allocated terminal not echo input.
$bSuccess = $oSsh.SetTtyMode("ECHO",0)
If ($bSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
; The modes set above are included in the PTY request.
$bSuccess = $oSsh.SendReqPty($iChannelNum,"xterm",80,24,0,0)
If ($bSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oSsh.SendReqShell($iChannelNum)
If ($bSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
$oSsh.Disconnect