Sample code for 30+ languages & platforms
AutoIt

Clear Accumulated SSH TTY Modes

See more SSH Examples

Demonstrates the Chilkat Ssh.ClearTtyModes method, which clears all TTY modes previously added with SetTtyMode. It takes no arguments. The next SendReqPty will not include the cleared modes.

Background: Because TTY modes accumulate on the Ssh object, they would otherwise carry over into every later PTY request on that object. ClearTtyModes resets that state — useful when one Ssh object opens several channels and each needs different terminal settings, or when you want a PTY created with the server's defaults.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  Demonstrates the Ssh.ClearTtyModes method, which clears all TTY modes previously added with
;  SetTtyMode.  It takes no arguments.

$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

;  Add a TTY mode, then discard it before requesting the PTY.
$bSuccess = $oSsh.SetTtyMode("ECHO",0)
If ($bSuccess = False) Then
    ConsoleWrite($oSsh.LastErrorText & @CRLF)
    Exit
EndIf

;  Clear the accumulated TTY modes.  The next SendReqPty will not include them.
$oSsh.ClearTtyModes 

;  Open a session channel.  A negative return value indicates failure.
Local $iChannelNum = $oSsh.OpenSessionChannel()
If ($iChannelNum < 0) Then
    ConsoleWrite($oSsh.LastErrorText & @CRLF)
    Exit
EndIf

;  This PTY request carries no custom TTY modes.
$bSuccess = $oSsh.SendReqPty($iChannelNum,"xterm",80,24,0,0)
If ($bSuccess = False) Then
    ConsoleWrite($oSsh.LastErrorText & @CRLF)
    Exit
EndIf

$oSsh.Disconnect