DataFlex
DataFlex
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 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.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.
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
// 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
// Request that the allocated terminal not echo input.
Get ComSetTtyMode Of hoSsh "ECHO" 0 To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
// The modes set above are included in the PTY request.
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
Get ComSendReqShell Of hoSsh iChannelNum To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
Send ComDisconnect To hoSsh
End_Procedure