PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_SshPort
string ls_Password
integer li_ChannelNum
string ls_TermType
integer li_WidthInChars
integer li_HeightInChars
integer li_WidthInPixels
integer li_HeightInPixels
li_Success = 0
// 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.
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
// Request an 80x24 xterm. Pixel dimensions of 0 mean unspecified.
ls_TermType = "xterm"
li_WidthInChars = 80
li_HeightInChars = 24
li_WidthInPixels = 0
li_HeightInPixels = 0
li_Success = loo_Ssh.SendReqPty(li_ChannelNum,ls_TermType,li_WidthInChars,li_HeightInChars,li_WidthInPixels,li_HeightInPixels)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// Start the shell now that the PTY is allocated.
li_Success = loo_Ssh.SendReqShell(li_ChannelNum)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
loo_Ssh.Disconnect()
destroy loo_Ssh