⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atremotexcopyunit.pas

📁 DELPHI 下远程控制源码
💻 PAS
字号:
unit AtRemoteXCopyUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls,IdGlobal, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient;

type
  TAtRemoteXCopyFm = class(TForm)
    Animate1: TAnimate;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label5: TLabel;
    Label1: TLabel;
    Label4: TLabel;
    Edit4: TEdit;
    Label6: TLabel;
    ProgressBar1: TProgressBar;
    Panel1: TPanel;
    BitBtn3: TBitBtn;
    BitBtn1: TBitBtn;
    CheckBox1: TCheckBox;
    BitBtn2: TBitBtn;
    RemoteCopyTcp: TIdTCPClient;
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  AtRemoteXCopyFm: TAtRemoteXCopyFm;

implementation

uses Unit1,Unit1UseUnit;

{$R *.dfm}

procedure TAtRemoteXCopyFm.BitBtn3Click(Sender: TObject);
var
   FileCount,TotalSize,FileSize,i:Integer;
   TheReadState,TheSFName:String;
   TheRemoteDir:String;
begin
  Self.Tag:=1;
  TheRemoteDir:=Edit4.Text;//移动的源目录
  if Form1.ConnectRemoteHost(RemoteCopyTcp,Form1.TheFileConnectRec) then
  begin
   i:=RemoteCopyTcp.ReadInteger; //读取连接后的标志
   try
     RemoteCopyTcp.Write('目录复制'+EOL);       //发送服务器命令
     RemoteCopyTcp.Write(Edit4.Text+EOL);       //发送源目录参数
     RemoteCopyTcp.Write(Edit3.Text+EOL);       //发送目的目录参数

     FileCount:=RemoteCopyTcp.ReadInteger;      //读文件总数
     TotalSize:=RemoteCopyTcp.ReadInteger;      //读目录尺寸
     Self.Caption:='远程需要移动:'+IntToStr(TotalSize)+'字节';
   except
     RemoteCopyTcp.Disconnect;
     Self.Caption:='网络断开';
     exit;
   end;
   
   ProgressBar1.Max:=TotalSize;
   ProgressBar1.Position:=0;       //设置进度器最大值
   Edit2.Text:='--'+IntToStr(FileCount)+'个';

   //读取进一步处理消息
   try
     TheReadState:=RemoteCopyTcp.ReadLn(EOL); //读接收状态
     if TheReadState='目录已经存在' then //如果是目录存在,则退出进一步操作
     begin
       Application.MessageBox('目标目录已经存在,'+
	      #10#13+'请删除该目录或选择移动到其它目录下!',				 
		'远程移动提示:',MB_OK+MB_ICONSTOP);
       RemoteCopyTcp.DisConnect;
       Close;
       exit;  
     end;
     
     TheSFName:=RemoteCopyTcp.ReadLn(EOL);    //读文件名----------2
     FileSize:=RemoteCopyTcp.ReadInteger;     //读文件大小--------3
     Edit1.Text:=ExtractFileName(TheSFName);   //显示文件名
     Edit3.Text:=ExtractFilePath(TheSFName);   //显示路径名
     Edit2.Text:='--'+IntToStr(FileCount)+
				  '个,正在移动第'+IntToStr(i)+'个';
     ProgressBar1.Position:=ProgressBar1.Position+FileSize; 
   except
      RemoteCopyTcp.Disconnect;
      Self.Caption:='网络传输错误!已经断开。';
      exit;
   end;
   //进一步操作
   i:=1;
   Repeat
      i:=i+1;
      Application.ProcessMessages;
      if Self.Tag=0 then 
	begin
	  RemoteCopyTcp.Disconnect;
	  Self.Caption:='网络被自己中断!';  
	  exit;
	end; 
      try	     
	TheReadState:=RemoteCopyTcp.ReadLn(EOL);  //读接收开始的状态--1
	Self.Caption:=TheReadState;
	if TheReadState='目录复制完毕' then break;//判断结束标志
	TheSFName:=RemoteCopyTcp.ReadLn(EOL);     //读文件名----------2
	FileSize:=RemoteCopyTcp.ReadInteger;      //读文件大小--------3
	Edit1.Text:=ExtractFileName(TheSFName);   //显示文件名
	Edit3.Text:=ExtractFilePath(TheSFName);   //显示路径名
	Edit2.Text:='--'+IntToStr(FileCount)+
		    '个,正在移动第'+IntToStr(i)+'个';
		  
	ProgressBar1.Position:=ProgressBar1.Position+FileSize;
      except
	RemoteCopyTcp.Disconnect;
	Self.Caption:='网络断开';
	exit;
      end;
   until TheReadState='目录复制完毕';
   beep;
   DelRemoteDir(TheRemoteDir,Form1.IdFTCPClient);
   Self.Caption:='远程移动完毕!';
   RemoteCopyTcp.Disconnect;
   if Self.CheckBox1.Checked then Close;
  end;
end;
procedure TAtRemoteXCopyFm.BitBtn2Click(Sender: TObject);
begin
  Self.Tag:=0;
end;

procedure TAtRemoteXCopyFm.BitBtn1Click(Sender: TObject);
begin
   Self.Tag:=0;
   RemoteCopyTcp.Disconnect;
   Self.Close;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -