Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set ssh [new_CkSsh]

set sshPort 22
set success [CkSsh_Connect $ssh "ssh.example.com" $sshPort]
if {$success == 0} then {
    puts [CkSsh_lastErrorText $ssh]
    delete_CkSsh $ssh
    exit
}

#  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.
set password "mySshPassword"

set success [CkSsh_AuthenticatePw $ssh "mySshLogin" $password]
if {$success == 0} then {
    puts [CkSsh_lastErrorText $ssh]
    delete_CkSsh $ssh
    exit
}

#  Add a TTY mode, then discard it before requesting the PTY.
set success [CkSsh_SetTtyMode $ssh "ECHO" 0]
if {$success == 0} then {
    puts [CkSsh_lastErrorText $ssh]
    delete_CkSsh $ssh
    exit
}

#  Clear the accumulated TTY modes.  The next SendReqPty will not include them.
CkSsh_ClearTtyModes $ssh

#  Open a session channel.  A negative return value indicates failure.
set channelNum [CkSsh_OpenSessionChannel $ssh]
if {$channelNum < 0} then {
    puts [CkSsh_lastErrorText $ssh]
    delete_CkSsh $ssh
    exit
}

#  This PTY request carries no custom TTY modes.
set success [CkSsh_SendReqPty $ssh $channelNum "xterm" 80 24 0 0]
if {$success == 0} then {
    puts [CkSsh_lastErrorText $ssh]
    delete_CkSsh $ssh
    exit
}

CkSsh_Disconnect $ssh

delete_CkSsh $ssh