Lianja
Lianja
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 Lianja Downloads
llSuccess = .F.
// 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.
loSsh = createobject("CkSsh")
lnSshPort = 22
llSuccess = loSsh.Connect("ssh.example.com",lnSshPort)
if (llSuccess = .F.) then
? loSsh.LastErrorText
release loSsh
return
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.
lcPassword = "mySshPassword"
llSuccess = loSsh.AuthenticatePw("mySshLogin",lcPassword)
if (llSuccess = .F.) then
? loSsh.LastErrorText
release loSsh
return
endif
// Open a session channel. A negative return value indicates failure.
lnChannelNum = loSsh.OpenSessionChannel()
if (lnChannelNum < 0) then
? loSsh.LastErrorText
release loSsh
return
endif
// Request that the allocated terminal not echo input.
llSuccess = loSsh.SetTtyMode("ECHO",0)
if (llSuccess = .F.) then
? loSsh.LastErrorText
release loSsh
return
endif
// The modes set above are included in the PTY request.
llSuccess = loSsh.SendReqPty(lnChannelNum,"xterm",80,24,0,0)
if (llSuccess = .F.) then
? loSsh.LastErrorText
release loSsh
return
endif
llSuccess = loSsh.SendReqShell(lnChannelNum)
if (llSuccess = .F.) then
? loSsh.LastErrorText
release loSsh
return
endif
loSsh.Disconnect()
release loSsh