Sample code for 30+ languages & platforms
Lua

Notify the SSH Server of a Terminal Resize

See more SSH Examples

Demonstrates the Chilkat Ssh.SendReqWindowChange method, which tells the server that the terminal dimensions changed. The arguments are the channel number, the new character width and height, and the pixel width and height. It may be sent any time after the PTY is allocated.

Background: When a user resizes a terminal window, full-screen remote programs such as vi, top, or less need to know the new size or they will keep drawing at the old dimensions. This request delivers that update, causing the server to signal the remote process (SIGWINCH on Unix) so it can redraw correctly.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Demonstrates the Ssh.SendReqWindowChange method, which notifies the server that the terminal
-- dimensions changed.  The 1st argument is the channel number, the 2nd and 3rd are the new
-- character width and height, and the 4th and 5th are the pixel width and height.

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

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

-- Allocate a PTY and start a shell.
success = ssh:send_req_pty(channelNum, "xterm", 80, 24, 0, 0)
if not success then
    print(ssh.last_error_text)
    return
end

success = ssh:send_req_shell(channelNum)
if not success then
    print(ssh.last_error_text)
    return
end

-- The user resized the terminal window -- tell the server the new dimensions.
local newWidthInChars = 132
local newHeightInRows = 43
local pixWidth = 0
local pixHeight = 0
success = ssh:send_req_window_change(channelNum, newWidthInChars, newHeightInRows, pixWidth, pixHeight)
if not success then
    print(ssh.last_error_text)
    return
end

print("Window change sent.")

ssh:disconnect()