用delphi客户端执行linux主机命令(100分)

  • 主题发起人 主题发起人 cfybyair
  • 开始时间 开始时间
C

cfybyair

Unregistered / Unconfirmed
GUEST, unregistred user!
用delphi执行远端linux主机程序。如何执行???
我参考了以下代码但是总出错不知道是什么原因!请执教!
procedure TForm1.Button1Click(Sender: TObject);
begin
 if ClientSocket1.Active then ClientSocket1.Active := False;
  if InputQuery(‘连接至:', ‘地址:', Server) then
   if Length(Server) > 0 then
    with ClientSocket1 do
    begin
     Address := Server;
     Active := True;
end;
end;
procedure TForm1.readfromhost(Sender:TObject;
Socket: TCustomWinSocket);
begin
 loginsend:=False;
 passsend:=False;
 count:=Socket.ReceiveBuf(InBuffer,High
(InBuffer));
 m_count:=0;
 while (m_count<count) do
begin
ch:=InBuffer[m_count];
if (ch=char(F_IAC)) then
begin
m_count:=m_count+1;
cmd:=InBuffer[m_count];
   if((cmd=char(F_DO))or(cmd=char
(F_WILL))or(cmd=char(F_DONT))or(cmd=char
(F_WONT))) then
begin
m_count:=m_count+1;
nOpt:=InBuffer[m_count];
if((nOpt=char(F_GOAHEAD))or
(nOpt=char(F_ECHO))) then
begin
if(cmd=char(F_DO)) then
begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_WILL);
reply[2]:=nOpt;
Socket.SendBuf(reply,Length(reply));
end;
if(cmd=char(F_WILL)) then
  begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_DO);
reply[2]:=nOpt;
Socket.SendBuf(reply,
Length(reply));
end;
end;
if((nOpt<>char(F_GOAHEAD))or(nOpt<>char(F_ECHO))) then
begin
if(cmd=char(F_DO)) then
begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_WONT);
reply[2]:=nOpt;
Socket.SendBuf(reply,
Length(reply));
end;
if(cmd=char(F_WILL)) then
begin
reply[0]:=char(F_IAC);
reply[1]:=char(F_DONT);
reply[2]:=nOpt;
Socket.SendBuf(reply,
Length(reply));
end;
end;
end;
end; //end F_IAC
if(ch<>char(F_IAC)) then
begin
m_string:=m_string+ch;
end;
m_count:=m_count+1;
  end;
  //假设编程者知道Unix的LOGIN和PASSWORD
  if(Length(m_string)>0) then
   begin
while ((Pos(‘login:',m_string)>0)and(not
loginsend)) do
begin
cmdtounix:=‘root'+#10+#13;
code:=Socket.SendBuf(cmdtounix,6);
loginsend:=True;
end;
while ((Pos(‘Password:',m_string)>0)and(not passsend)) do
begin
cmdtounix:=‘root'+#13+#10;
code:=Socket.SendBuf(cmdtounix,6);
passsend:=True;
m_string:=‘';
end;
if ( Pos(‘jcy:/#>',m_string)>0) then
begin
cmdtounix:=‘mkdir /tmp/fang'+#
13+#10;
code:=Socket.SendBuf(cmdtounix,
Length(cmdtounix));
if code>0 then
begin
ClientSocket1.Active:=False;
Close;
end;
end;
   end;
  end;
end;

 
后退
顶部