PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_SshPort
string ls_Password
integer li_ChannelNum
integer li_NewWidthInChars
integer li_NewHeightInRows
integer li_PixWidth
integer li_PixHeight
li_Success = 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.
loo_Ssh = create oleobject
li_rc = loo_Ssh.ConnectToNewObject("Chilkat.Ssh")
if li_rc < 0 then
destroy loo_Ssh
MessageBox("Error","Connecting to COM object failed")
return
end if
li_SshPort = 22
li_Success = loo_Ssh.Connect("ssh.example.com",li_SshPort)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// 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.
ls_Password = "mySshPassword"
li_Success = loo_Ssh.AuthenticatePw("mySshLogin",ls_Password)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// Open a session channel. A negative return value indicates failure.
li_ChannelNum = loo_Ssh.OpenSessionChannel()
if li_ChannelNum < 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// Allocate a PTY and start a shell.
li_Success = loo_Ssh.SendReqPty(li_ChannelNum,"xterm",80,24,0,0)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
li_Success = loo_Ssh.SendReqShell(li_ChannelNum)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// The user resized the terminal window -- tell the server the new dimensions.
li_NewWidthInChars = 132
li_NewHeightInRows = 43
li_PixWidth = 0
li_PixHeight = 0
li_Success = loo_Ssh.SendReqWindowChange(li_ChannelNum,li_NewWidthInChars,li_NewHeightInRows,li_PixWidth,li_PixHeight)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
Write-Debug "Window change sent."
loo_Ssh.Disconnect()
destroy loo_Ssh