欢迎来到学术参考网

使用indy的IdTcpServer,IdTcpclient传输文件

发布时间:2015-07-09 11:08

接受部分(有个用户和密码check,你取消就可以)
procedure erverExecute(AThread: TIdPeerThread);
var
 FStream  : TFileStream;
 FileName  : String;
 CmdStr   : String;
begin
  CmdStr :=();
  if CompareStr(Copy(CmdStr,1,6),‘SEND‘)=0 then
   begin //1
  Delete(CmdStr,1,6);
  Cmd := ‘上传文件‘;
  FileName := CmdStr;
  if FileExists(ExtractFilePath(e)+FileName) then
  DeleteFile(ExtractFilePath(e)+FileName);
  try
   FStream := (ExtractFilePath(e)+FileName,FmCreate);
   ream(FStream,2048,true);
  Finally
   ;
   nect;
  end;
   end  //1
  else if CompareStr(Copy(CmdStr,1,6),‘AGET‘)=0 then
   begin //2
  Delete(CmdStr,1,6);
  Cmd := ‘下载文件‘;
  FileName := CmdStr;
  if FileExists(ExtractFilePath(e)+FileName) then
  begin
   try
    FStream := (ExtractFilePath(e)+FileName,FmOpenRead);
    tream(FStream,True,False);
   Finally
    ;
    nect;
   end;
  end
  else
  begin
   n(‘Failed‘);
   nect;
  end;
   end //2
  else if CompareStr(Copy(CmdStr,1,6),‘USER‘)=0 then
   begin //3
  Delete(CmdStr,1,6);
  User := UpperCase(Trim(DecryptString(CmdStr,20504))); //CmdStr;
  if CompareStr(User,‘XDM‘)=0 then
  begin
   (‘User: ‘+User);
   CmdStr :=‘‘;
  end
  else
  begin
   (‘User: ‘+User+‘ 非法登陆,已关闭连接‘);
   CmdStr := ‘‘;
   n(‘Failed‘);
   nect;
  end;
   end  //3
  else if CompareStr(Copy(CmdStr,1,6),‘PASS‘)=0 then
   begin //4


  Delete(CmdStr,1,6);
  Password := DecryptString(CmdStr,20504); //CmdStr;
  if CompareStr(Password,‘123abc‘)=0 then
  begin
   (‘Login..........Accepted‘);
   (‘Connected......‘+DateTimeToStr(Now));
   CmdStr := ‘‘;
   n(‘Accepted‘);
  end
  else
  begin
   (‘Password Wrong...Login Failure‘);
   n(‘Failed‘);
   CmdStr :=‘‘;
   nect;
  end;
   end;  //4
end;

主要发送部分
procedure dClick(Sender: TObject);
var
 FStream : TFileStream;
begin
 if ted then begin
   n(‘SEND‘+ExtractFileName(FileName));
   if FileName = ‘‘ then
  MessageBox(Handle,‘没有选择文件‘,‘Error‘,MB_OK)
   else begin
  try
  FStream := (FileName,FmOpenRead);
  on := 0;
  (0,0);
  tream(FStream,true,false);
  Finally
  ;
  nect;
  end;
  (‘Transferred OK‘);
   end;
 end
 else
  begin
   MessageBox(Handle,‘没有连接服务器‘,‘Error‘,MB_Ok);
  end;
end;

上一篇:利用鼠标键盘钩子截获密码

下一篇:用VB学做“黑客”程序