Sample code for 30+ languages & platforms
Delphi DLL

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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
ssh: HCkSsh;
sshPort: Integer;
password: PWideChar;
channelNum: Integer;

begin
success := False;

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

ssh := CkSsh_Create();

sshPort := 22;
success := CkSsh_Connect(ssh,'ssh.example.com',sshPort);
if (success = False) then
  begin
    Memo1.Lines.Add(CkSsh__lastErrorText(ssh));
    Exit;
  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.
password := 'mySshPassword';

success := CkSsh_AuthenticatePw(ssh,'mySshLogin',password);
if (success = False) then
  begin
    Memo1.Lines.Add(CkSsh__lastErrorText(ssh));
    Exit;
  end;

//  Open a session channel.  A negative return value indicates failure.
channelNum := CkSsh_OpenSessionChannel(ssh);
if (channelNum < 0) then
  begin
    Memo1.Lines.Add(CkSsh__lastErrorText(ssh));
    Exit;
  end;

//  Request that the allocated terminal not echo input.
success := CkSsh_SetTtyMode(ssh,'ECHO',0);
if (success = False) then
  begin
    Memo1.Lines.Add(CkSsh__lastErrorText(ssh));
    Exit;
  end;

//  The modes set above are included in the PTY request.
success := CkSsh_SendReqPty(ssh,channelNum,'xterm',80,24,0,0);
if (success = False) then
  begin
    Memo1.Lines.Add(CkSsh__lastErrorText(ssh));
    Exit;
  end;

success := CkSsh_SendReqShell(ssh,channelNum);
if (success = False) then
  begin
    Memo1.Lines.Add(CkSsh__lastErrorText(ssh));
    Exit;
  end;

CkSsh_Disconnect(ssh);

CkSsh_Dispose(ssh);