Sample code for 30+ languages & platforms
Lua

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

Lua
local chilkat = require("chilkat")

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

local ssh = chilkat.Ssh.new()

local sshPort = 22
local success = ssh:connect("ssh.example.com", sshPort)
if not success then
    print(ssh.last_error_text)
    return
end

-- 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 password = "mySshPassword"

success = ssh:authenticate_pw("mySshLogin", password)
if not success then
    print(ssh.last_error_text)
    return
end

-- Add a TTY mode, then discard it before requesting the PTY.
success = ssh:set_tty_mode("ECHO", 0)
if not success then
    print(ssh.last_error_text)
    return
end

-- Clear the accumulated TTY modes.  The next SendReqPty will not include them.
ssh:clear_tty_modes()

-- Open a session channel.  A negative return value indicates failure.
local channelNum = ssh:open_session_channel()
if channelNum < 0 then
    print(ssh.last_error_text)
    return
end

-- This PTY request carries no custom TTY modes.
success = ssh:send_req_pty(channelNum, "xterm", 80, 24, 0, 0)
if not success then
    print(ssh.last_error_text)
    return
end

ssh:disconnect()