Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
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 Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Ssh;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ssh: TSsh;
sshPort: Integer;
password: string;
channelNum: Integer;
begin
success := False;
// Demonstrates the Ssh.ClearTtyModes method, which clears all TTY modes previously added with
// SetTtyMode. It takes no arguments.
ssh := TSsh.Create;
sshPort := 22;
success := ssh.Connect('ssh.example.com',sshPort);
if (success = False) then
begin
WriteLn(ssh.LastErrorText);
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 := ssh.AuthenticatePw('mySshLogin',password);
if (success = False) then
begin
WriteLn(ssh.LastErrorText);
Exit;
end;
// Add a TTY mode, then discard it before requesting the PTY.
success := ssh.SetTtyMode('ECHO',0);
if (success = False) then
begin
WriteLn(ssh.LastErrorText);
Exit;
end;
// Clear the accumulated TTY modes. The next SendReqPty will not include them.
ssh.ClearTtyModes();
// Open a session channel. A negative return value indicates failure.
channelNum := ssh.OpenSessionChannel();
if (channelNum < 0) then
begin
WriteLn(ssh.LastErrorText);
Exit;
end;
// This PTY request carries no custom TTY modes.
success := ssh.SendReqPty(channelNum,'xterm',80,24,0,0);
if (success = False) then
begin
WriteLn(ssh.LastErrorText);
Exit;
end;
ssh.Disconnect();
ssh.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.