unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdTelnet, StdCtrls;
type
TForm1 =
class(TForm)
IdTelnet1: TIdTelnet;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure IdTelnet1DataAvailable(Sender: TIdTelnet;
const Buffer:
String);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure IdTelnet1Connected(Sender: TObject);
private
{ Private-Deklarationen }
FUserSent: Boolean;
FPassSent: Boolean;
FCmdSent: Boolean;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.IdTelnet1Connected(Sender: TObject);
begin
FUserSent := False;
FPassSent := False;
FCmdSent := False;
end;
procedure TForm1.IdTelnet1DataAvailable(Sender: TIdTelnet;
const Buffer:
String);
begin
if (Pos('
ogin:',Buffer) > 0)
and not FUserSent
then
begin
IdTelnet1.WriteLn('
myusername');
FUserSent := True;
end;
if (Pos('
ssword:',Buffer) > 0)
and not FPassSent
then
begin
IdTelnet1.WriteLn('
mypassword');
FPassSent := True;
end;
if (Pos('
user@machine /home/user>',Buffer) > 0)
and not FCmdSent
then
begin
IdTelnet1.WriteLn('
ls -l');
FCmdSent := True;
end;
Memo1.Lines.Add(Buffer);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
IdTelnet1.Connect;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
IdTelnet1.Disconnect;
Close;
end;
end.