仍摘自网上:程序中FTP下载采用了INDY的FTP控件(DELPHI7自带的),开发环境是(Win2000,Delphi 7)procedure TFrmMain.BitBtn1Click(Sender: TObject);var tmpini:Tinifile; tver,tsys:string;begin BitBtn2.Click; if MessageDlg('升级前请务必关闭业务管理系统,你已经关闭了吗?', mtWarning, [mbYes, mbNo], 0) = mrNo then begin showmessage('只有在关闭了业务管理系统后才能升级!请先关闭系统!'); exit; end; BitBtn4.Visible:=True; tmpini:=TiniFile.Create(extractfilepath(application.ExeName)+'system.ini'); tver:=tmpini.ReadString('system','Version',''); tsys:=tmpini.ReadString('system','Program',''); if tver='' then begin tmpini.WriteString('system','Version','1.0'); tver:='1.0'; end; if tsys='' then tsys:='branch'; tmpini.Free; getnewfile('set',tver,tsys); if tver<NewVer then begin getnewfile('Files',tver,tsys); end else showmessage('已经是最新版本!');end;procedure TFrmMain.getnewFile(sfile:string;const tver:string='';tsys:string='branch');var appini,appini1:Tinifile; i,compr:integer; tfiles,dfiles,tdir:string;begin idFTP1.Host:=LabeledEdit3.Text; idFTP1.Username:=LabeledEdit1.Text; idFTP1.Password:=labeledEdit2.Text; if not idFTP1.Connected then try idFTP1.Connect; except showmessage('不能连接远程服务器,请查原因!'); abort; end; idFTP1.ChangeDir('/down/'); IdFTP1.TransferType := ftBinary; //下载配置文件 if sfile='set' then begin dfiles:=extractfilepath(application.ExeName)+'UPdate.ini'; BytesToTransfer:=idFTP1.Size('update.ini'); idFTP1.Get('update.ini',dfiles,True); appini:=Tinifile.Create(extractfilepath(application.ExeName)+'update.ini'); NewVer:=appini.ReadString('CanDown','Version',''); oldVer:=Tver; appini.Free; end else begin //下载升级文件 //检查下载文件保存路径是否存在 tdir:=LabeledEdit4.Text; if tdir[length(tdir)]<>'/' then tdir:=tdir+'/'; if not directoryexists(tdir+'update/') then mkdir(tdir+'update/'); appini:=Tinifile.Create(extractfilepath(application.ExeName)+'update.ini'); icount:=appini.ReadInteger(tsys,'FileCounts',0); compr:=appini.ReadInteger(tsys,'compress',0); if (OldVer<>'') and (OldVer>NewVer) then begin showmessage('已经是最新版本了!'); appini.Free; exit; end; if OldVer<NewVer then begin appini1:=TiniFile.Create(extractfilepath(application.ExeName)+'system.ini'); appini1.WriteString('system','Version',Newver); appini1.Free; end; if icount>0 then begin idFTP1.ChangeDir('/down/'+tsys); for i:=1 to icount do begin tfiles:=appini.ReadString(tsys,'File'+inttostr(i),''); if tfiles<>'' then begin staticText2.Caption:='正在下载文件:'+tfiles; BytesToTransfer:=idFTP1.Size(tfiles); idFTP1.Get(tfiles,tdir+'update/'+tfiles,True); end; end; appini.Free; CopyFileToUse(compr,tsys); end; end;end;//将新下载的文件拷贝到程序目录中procedure TFrmMain.CopyFileToUse(Compr:integer;const tsys:string='branch');var appini:Tinifile; i,j:integer; tfiles,tdir,tmp1:string;begin tdir:=LabeledEdit4.Text; if tdir[length(tdir)]<>'/' then tdir:=tdir+'/'; appini:=Tinifile.Create(extractfilepath(application.ExeName)+'/update.ini'); i:=appini.ReadInteger(tsys,'FileCounts',0); if i>0 then begin for j:=1 to i do begin tfiles:=appini.ReadString(tsys,'File'+inttostr(j),''); if tfiles<>'' then begin staticText2.Caption:='正在更新文件:'+tfiles; if compr=1 then begin tmp1:=tdir+'rar e '+tdir+'update/'+tfiles+' -y '+tdir; // WinexecAndWait32(tmp1,sw_show); WinexecAndWait32(tmp1,sw_hide); end else CopyFile(tdir+'update/'+tfiles,tdir+tfiles); end;