Sample code for 30+ languages & platforms
PowerBuilder

Set a TTY Mode for an SSH PTY Request

See more SSH Examples

Demonstrates the Chilkat Ssh.SetTtyMode method, which adds or updates one TTY mode to be included in a later SendReqPty request. The first argument is the mode name and the second is its integer value. Call it once per mode, before requesting the PTY.

Background: TTY modes are the terminal settings a PTY is created with — the same knobs stty exposes. The classic use is SetTtyMode("ECHO", 0), which stops the terminal from echoing input; that is how a password prompt keeps typed characters off the screen. Modes accumulate on the object and are sent with the next PTY request.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_SshPort
string ls_Password
integer li_ChannelNum

li_Success = 0

//  Demonstrates the Ssh.SetTtyMode method, which adds or updates one TTY mode to be included in
//  a later SendReqPty request.  The 1st argument is the mode name and the 2nd is its integer
//  value.  Call it once per mode, before SendReqPty.

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 that the allocated terminal not echo input.
li_Success = loo_Ssh.SetTtyMode("ECHO",0)
if li_Success = 0 then
    Write-Debug loo_Ssh.LastErrorText
    destroy loo_Ssh
    return
end if

//  The modes set above are included in the PTY request.
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

loo_Ssh.Disconnect()


destroy loo_Ssh