DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSsh
Integer iSshPort
String sPassword
Integer iChannelNum
String sTemp1
Move False To iSuccess
// Demonstrates the Ssh.ClearTtyModes method, which clears all TTY modes previously added with
// SetTtyMode. It takes no arguments.
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
// Add a TTY mode, then discard it before requesting the PTY.
Get ComSetTtyMode Of hoSsh "ECHO" 0 To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
// Clear the accumulated TTY modes. The next SendReqPty will not include them.
Send ComClearTtyModes To hoSsh
// 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
// This PTY request carries no custom TTY modes.
Get ComSendReqPty Of hoSsh iChannelNum "xterm" 80 24 0 0 To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
Send ComDisconnect To hoSsh
End_Procedure