Sample code for 30+ languages & platforms
AutoIt

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

AutoIt
Local $bSuccess = False

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

$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

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

;  Allocate a PTY and start a shell.
$bSuccess = $oSsh.SendReqPty($iChannelNum,"xterm",80,24,0,0)
If ($bSuccess = False) Then
    ConsoleWrite($oSsh.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oSsh.SendReqShell($iChannelNum)
If ($bSuccess = False) Then
    ConsoleWrite($oSsh.LastErrorText & @CRLF)
    Exit
EndIf

;  The user resized the terminal window -- tell the server the new dimensions.
Local $iNewWidthInChars = 132
Local $iNewHeightInRows = 43
Local $iPixWidth = 0
Local $iPixHeight = 0
$bSuccess = $oSsh.SendReqWindowChange($iChannelNum,$iNewWidthInChars,$iNewHeightInRows,$iPixWidth,$iPixHeight)
If ($bSuccess = False) Then
    ConsoleWrite($oSsh.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Window change sent." & @CRLF)

$oSsh.Disconnect