Sample code for 30+ languages & platforms
Lianja

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

Lianja
llSuccess = .F.

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

loSsh = createobject("CkSsh")

lnSshPort = 22
llSuccess = loSsh.Connect("ssh.example.com",lnSshPort)
if (llSuccess = .F.) then
    ? loSsh.LastErrorText
    release loSsh
    return
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.
lcPassword = "mySshPassword"

llSuccess = loSsh.AuthenticatePw("mySshLogin",lcPassword)
if (llSuccess = .F.) then
    ? loSsh.LastErrorText
    release loSsh
    return
endif

//  Open a session channel.  A negative return value indicates failure.
lnChannelNum = loSsh.OpenSessionChannel()
if (lnChannelNum < 0) then
    ? loSsh.LastErrorText
    release loSsh
    return
endif

//  Allocate a PTY and start a shell.
llSuccess = loSsh.SendReqPty(lnChannelNum,"xterm",80,24,0,0)
if (llSuccess = .F.) then
    ? loSsh.LastErrorText
    release loSsh
    return
endif

llSuccess = loSsh.SendReqShell(lnChannelNum)
if (llSuccess = .F.) then
    ? loSsh.LastErrorText
    release loSsh
    return
endif

//  The user resized the terminal window -- tell the server the new dimensions.
lnNewWidthInChars = 132
lnNewHeightInRows = 43
lnPixWidth = 0
lnPixHeight = 0
llSuccess = loSsh.SendReqWindowChange(lnChannelNum,lnNewWidthInChars,lnNewHeightInRows,lnPixWidth,lnPixHeight)
if (llSuccess = .F.) then
    ? loSsh.LastErrorText
    release loSsh
    return
endif

? "Window change sent."

loSsh.Disconnect()


release loSsh