PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkSsh.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the Ssh.ClearTtyModes method, which clears all TTY modes previously added with
; SetTtyMode. It takes no arguments.
ssh.i = CkSsh::ckCreate()
If ssh.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
sshPort.i = 22
success = CkSsh::ckConnect(ssh,"ssh.example.com",sshPort)
If success = 0
Debug CkSsh::ckLastErrorText(ssh)
CkSsh::ckDispose(ssh)
ProcedureReturn
EndIf
; 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.
password.s = "mySshPassword"
success = CkSsh::ckAuthenticatePw(ssh,"mySshLogin",password)
If success = 0
Debug CkSsh::ckLastErrorText(ssh)
CkSsh::ckDispose(ssh)
ProcedureReturn
EndIf
; Add a TTY mode, then discard it before requesting the PTY.
success = CkSsh::ckSetTtyMode(ssh,"ECHO",0)
If success = 0
Debug CkSsh::ckLastErrorText(ssh)
CkSsh::ckDispose(ssh)
ProcedureReturn
EndIf
; Clear the accumulated TTY modes. The next SendReqPty will not include them.
CkSsh::ckClearTtyModes(ssh)
; Open a session channel. A negative return value indicates failure.
channelNum.i = CkSsh::ckOpenSessionChannel(ssh)
If channelNum < 0
Debug CkSsh::ckLastErrorText(ssh)
CkSsh::ckDispose(ssh)
ProcedureReturn
EndIf
; This PTY request carries no custom TTY modes.
success = CkSsh::ckSendReqPty(ssh,channelNum,"xterm",80,24,0,0)
If success = 0
Debug CkSsh::ckLastErrorText(ssh)
CkSsh::ckDispose(ssh)
ProcedureReturn
EndIf
CkSsh::ckDisconnect(ssh)
CkSsh::ckDispose(ssh)
ProcedureReturn
EndProcedure