Sample code for 30+ languages & platforms
PowerBuilder

Clear Accumulated SSH TTY Modes

See more SSH Examples

Demonstrates the Chilkat Ssh.ClearTtyModes method, which clears all TTY modes previously added with SetTtyMode. It takes no arguments. The next SendReqPty will not include the cleared modes.

Background: Because TTY modes accumulate on the Ssh object, they would otherwise carry over into every later PTY request on that object. ClearTtyModes resets that state — useful when one Ssh object opens several channels and each needs different terminal settings, or when you want a PTY created with the server's defaults.

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.ClearTtyModes method, which clears all TTY modes previously added with
//  SetTtyMode.  It takes no arguments.

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

//  Add a TTY mode, then discard it before requesting the PTY.
li_Success = loo_Ssh.SetTtyMode("ECHO",0)
if li_Success = 0 then
    Write-Debug loo_Ssh.LastErrorText
    destroy loo_Ssh
    return
end if

//  Clear the accumulated TTY modes.  The next SendReqPty will not include them.
loo_Ssh.ClearTtyModes()

//  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

//  This PTY request carries no custom TTY modes.
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

loo_Ssh.Disconnect()


destroy loo_Ssh