Sample code for 30+ languages & platforms
Visual Basic 6.0

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 Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
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.

Dim ssh As New ChilkatSsh

Dim sshPort As Long
sshPort = 22
success = ssh.Connect("ssh.example.com",sshPort)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
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.
Dim password As String
password = "mySshPassword"

success = ssh.AuthenticatePw("mySshLogin",password)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

'  Open a session channel.  A negative return value indicates failure.
Dim channelNum As Long
channelNum = ssh.OpenSessionChannel()
If (channelNum < 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

'  Allocate a PTY and start a shell.
success = ssh.SendReqPty(channelNum,"xterm",80,24,0,0)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

success = ssh.SendReqShell(channelNum)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

'  The user resized the terminal window -- tell the server the new dimensions.
Dim newWidthInChars As Long
newWidthInChars = 132
Dim newHeightInRows As Long
newHeightInRows = 43
Dim pixWidth As Long
pixWidth = 0
Dim pixHeight As Long
pixHeight = 0
success = ssh.SendReqWindowChange(channelNum,newWidthInChars,newHeightInRows,pixWidth,pixHeight)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

Debug.Print "Window change sent."

ssh.Disconnect