DataFlex
DataFlex
Request a Pseudo-Terminal (PTY) over SSH
See more SSH Examples
Demonstrates the Chilkat Ssh.SendReqPty method, which requests a pseudo-terminal for a session channel. The arguments are the channel number, the terminal type, the character width and height, and the pixel width and height. It must be sent before the primary exec or shell request.
Background: A PTY makes the remote side behave as though a real terminal is attached, which matters for programs that draw screens, prompt for passwords, or colorize output — many refuse to run interactively without one. The terminal type (such as
xterm) tells the remote program what escape sequences it may use. Pixel dimensions are commonly 0, meaning unspecified.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSsh
Integer iSshPort
String sPassword
Integer iChannelNum
String sTermType
Integer iWidthInChars
Integer iHeightInChars
Integer iWidthInPixels
Integer iHeightInPixels
String sTemp1
Move False To iSuccess
// Demonstrates the Ssh.SendReqPty method, which requests a pseudo-terminal for a session
// channel. The 1st argument is the channel number, the 2nd is the terminal type, the 3rd and
// 4th are the character width and height, and the 5th and 6th are the pixel width and height.
// It must be sent before the primary exec or shell request.
Get Create (RefClass(cComChilkatSsh)) To hoSsh
If (Not(IsComObjectCreated(hoSsh))) Begin
Send CreateComObject of hoSsh
End
Move 22 To iSshPort
Get ComConnect Of hoSsh "ssh.example.com" iSshPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
// 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.
Move "mySshPassword" To sPassword
Get ComAuthenticatePw Of hoSsh "mySshLogin" sPassword To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
// Open a session channel. A negative return value indicates failure.
Get ComOpenSessionChannel Of hoSsh To iChannelNum
If (iChannelNum < 0) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
// Request an 80x24 xterm. Pixel dimensions of 0 mean unspecified.
Move "xterm" To sTermType
Move 80 To iWidthInChars
Move 24 To iHeightInChars
Move 0 To iWidthInPixels
Move 0 To iHeightInPixels
Get ComSendReqPty Of hoSsh iChannelNum sTermType iWidthInChars iHeightInChars iWidthInPixels iHeightInPixels To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
// Start the shell now that the PTY is allocated.
Get ComSendReqShell Of hoSsh iChannelNum To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
Send ComDisconnect To hoSsh
End_Procedure