Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oSsh
LOCAL nSshPort
LOCAL cPassword
LOCAL nChannelNum
LOCAL nNewWidthInChars
LOCAL nNewHeightInRows
LOCAL nPixWidth
LOCAL nPixHeight
nSuccess := 0
// 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 := CreateObject("Chilkat.Ssh")
nSshPort := 22
nSuccess := oSsh:Connect("ssh.example.com", nSshPort)
IF (nSuccess == 0)
? oSsh:LastErrorText
oSsh:destroy()
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.
cPassword := "mySshPassword"
nSuccess := oSsh:AuthenticatePw("mySshLogin", cPassword)
IF (nSuccess == 0)
? oSsh:LastErrorText
oSsh:destroy()
RETURN
ENDIF
// Open a session channel. A negative return value indicates failure.
nChannelNum := oSsh:OpenSessionChannel()
IF (nChannelNum < 0)
? oSsh:LastErrorText
oSsh:destroy()
RETURN
ENDIF
// Allocate a PTY and start a shell.
nSuccess := oSsh:SendReqPty(nChannelNum, "xterm", 80, 24, 0, 0)
IF (nSuccess == 0)
? oSsh:LastErrorText
oSsh:destroy()
RETURN
ENDIF
nSuccess := oSsh:SendReqShell(nChannelNum)
IF (nSuccess == 0)
? oSsh:LastErrorText
oSsh:destroy()
RETURN
ENDIF
// The user resized the terminal window -- tell the server the new dimensions.
nNewWidthInChars := 132
nNewHeightInRows := 43
nPixWidth := 0
nPixHeight := 0
nSuccess := oSsh:SendReqWindowChange(nChannelNum, nNewWidthInChars, nNewHeightInRows, nPixWidth, nPixHeight)
IF (nSuccess == 0)
? oSsh:LastErrorText
oSsh:destroy()
RETURN
ENDIF
? "Window change sent."
oSsh:Disconnect()
oSsh:destroy()