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

📄 uploadunit.~pas

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

interface

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

type
  TUpLoadFm = class(TForm)
    Panel1: TPanel;
    Bevel1: TBevel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    ProgressBar1: TProgressBar;
    Animate1: TAnimate;
    CheckBox1: TCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    UpLoadTcp: TIdTCPClient;
    BitBtn3: TBitBtn;
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure Edit3MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
    UpLoadFile:String;
  public
    { Public declarations }
  end;

var
  UpLoadFm: TUpLoadFm;

implementation

uses Unit1;

{$R *.dfm}

procedure TUpLoadFm.BitBtn2Click(Sender: TObject);
var
  RetStr:String;   
  iReturn:integer;
  ReadBuf:array[1..32768] of byte;
  ReadCount:integer;
  ReadF:file;
  TheFLen,FLen:integer;
  TheIntPos:Int64;
begin
  UpLoadFile:=Edit2.Text+Edit1.Text;
  if Not FileExists(UpLoadFile) then
  begin
     Self.Caption:='请重新选择文件,该文件不存在!';
     Beep; exit;         
  end;
  try
   AssignFile(ReadF,UpLoadFile);
   FileMode:=0;
   Reset(ReadF,1);
   TheFLen:=FileSize(ReadF);
   Seek(ReadF,0);
  except
    CloseFile(ReadF);
    Self.Caption:='文件读取失败!请重新设置文件权限';
    Beep;exit;
  end;
  if Form1.ConnectRemoteHost(UpLoadTcp,Form1.TheFileConnectRec) then
  begin //============================================================连接的操作
     Animate1.Active:=True;
     Bitbtn2.Enabled:=False;
     Bitbtn1.Enabled:=False;
     iReturn:=UpLoadTcp.ReadInteger;
     if iReturn<>1 then
     begin
       CloseFile(ReadF);
       Self.Caption:='远程网络验证失败!';
       UpLoadTcp.Disconnect;
       Animate1.Active:=False;
       beep;  exit; 	     
     end;
      
     try //发送下载的文件
       UpLoadTcp.Write('文件上传'+EOL);           //1-------SendfileCMD
       UpLoadTcp.Write(Edit3.Text+Edit1.Text+EOL);//2-------SendfileName
       UpLoadTcp.WriteInteger(TheFLen);
       ReadCount:=0; 
       ProgressBar1.max:=TheFLen;
       
       Repeat
         UpLoadTcp.OpenWriteBuffer;     	 
	 BlockRead(ReadF,ReadBuf,sizeof(ReadBuf),ReadCount);
	 UpLoadTcp.WriteBuffer(ReadBuf,ReadCount);
	 UpLoadTcp.CloseWriteBuffer;
	 ProgressBar1.position:=ProgressBar1.position+ReadCount;
	 TheIntPos:=ProgressBar1.position;
	 self.Caption:='正在上传:'
		    +IntToStr(TheIntPos*100 div TheFLen)+'%';
       Until ProgressBar1.position=ProgressBar1.Max;          
     except
       Self.Caption:='文件发送失败!请检查网络是否正常。';
       UpLoadTcp.Disconnect;
       CloseFile(ReadF);
       Animate1.Active:=False;
       exit;Beep;
     end;
       UpLoadTcp.Disconnect;
       Self.Caption:='文件发送完毕!共发送:'
			+IntToStr(TheFLen)+'字节';
       CloseFile(ReadF);
       if Self.Tag=1 then 
	 if DeleteFile(UpLoadFile)=False then
	  Application.MessageBox('本地文件删除失败,请检查该文件是否正在运行或为只读!',
			      '删除提示:',
			      MB_OK+MB_ICONSTOP);      
       Animate1.Active:=False;
       Bitbtn2.Enabled:=False;
       Bitbtn1.Enabled:=True;
       if CheckBox1.Checked then close;
       exit;Beep;
  end;//==============================================================连接的操作      
  CloseFile(ReadF);
  Self.Caption:='请检查网络连接是否正常!';
  Animate1.Active:=False;
  Beep;
end;

procedure TUpLoadFm.BitBtn1Click(Sender: TObject);
begin
   UpLoadTcp.Disconnect;
   close;
end;

procedure TUpLoadFm.BitBtn3Click(Sender: TObject);
begin
    UpLoadTcp.Disconnect;
    close;
end;

procedure TUpLoadFm.Edit3MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
   (Sender as TEdit).Hint:=(Sender as TEdit).Text;
end;

end.

⌨️ 快捷键说明

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