用到临界区 保护写日志的函数;
递归函数 删除目录下的所有文件;
循环创建或判断FTP的目录;
可改进的地方:循环压缩深层次目录的所以文件; 实现断点续传,或断点下载;
1 {******************************************************************************* 2 Copyright (C), 2014-2020, aicaipiao 3 File name: UFtpContentThd.pas 4 Author: lipingchen 5 Version: 6 Date: 20140929 7 Description: 8 Others: 9 Function List: 10 1.Date:2015.03.31 11 Author: liping.chen 12 Modification: 解压缩,FTP遍历创建新目录,上传 13 *******************************************************************************} 14 unit UFtpContentThd; 15 16 interface 17 18 uses 19 Classes,Forms,Dialogs,SysUtils,Windows,VCLZip,VCLUnZip,IdFTP,IdFTPList,fClientDataModule, 20 IdFTPListParseWindowsNT,IdAllFTPListParsers,DateUtils,SyncObjs; 21 22 type 23 TLogMsgProc = procedure (AMsg: string; const blnIsErrorMsg: boolean = False; const BoolSaveToFile: Boolean = True); 24 25 TFtpContentThd = class(TThread) 26 private 27 FStart_Date,FEnd_Date,FNextDate :TDateTime;// 获取起始时间\获取结束时间\增加分钟 计算出结束时间 28 29 FCount :Integer; 30 FContent: wideString; 31 protected 32 ziper:TVCLZip; 33 IdFTP: TIdFTP; 34 FLogMsg: TLogMsgProc; 35 Filename:string; //生成压缩文件名 36 FMessage: string; //消息 37 ZipUpLoadDir,ZipUpLoadDirTemp:string; //上传FTP的路径 38 FDeptID:string; //出票点ID 39 pub_Critical: TCriticalSection; //临界区 40 //-------------- 41 procedure DoPostContent(var HasData: boolean); 42 //定区间 43 function Get_Bak_Date : Boolean; //获取时间段 44 //取,存,压缩 45 Function Get_ContentByDate(var HasData: boolean) : Boolean; // 根据推送的时间段,从票据打印表中取出数据获取,存为txt 46 //上传 47 Function UpLoad_Content_Zip :Boolean; //上传Zip包 48 //更新 49 Function Update_Content_Bak_Date : Boolean; 50 public 51 constructor Create(LogMsgProc: TLogMsgProc); 52 procedure LogInfo(AMsg: string; const blnIsErrorMsg: boolean = False; const BoolSaveToFile: Boolean = True); 53 destructor Destroy;override; 54 function CreatFtpDir(UpLoadDir:string): Boolean; //遍历当前FTP文件夹, 创建新目录或更改路径 55 function DeleteDirectory(NowPath: string): Boolean; // 循环删除整个目录下的所有文件包括文件夹 56 function Zip(ZipMode,packSize:Integer;ZipFile,UnzipDir:string):Boolean; 57 protected 58 procedure Execute; override; 59 end; 60 61 var 62 FtpContentThd:TFtpContentThd; 63 implementation 64 uses 65 UPubTypeVarCon,UFrmMain,UPubFuncProc; 66 67 { TFtpContentThd } 68 69 constructor TFtpContentThd.Create(LogMsgProc: TLogMsgProc); 70 var 71 sFilePath:string; 72 begin 73 sFilePath:=ExtractFilePath(Application.ExeName); 74 if sFilePath[Length(sFilePath)] <> ‘\‘ then sFilePath := sFilePath + ‘\‘; 75 pub_UnZipFileSaveDir:=sFilePath+‘PostContentRunLog\ConTxt‘; 76 pub_ZipFileSaveDir:=sFilePath+ ‘PostContentRunLog\ConZip‘; 77 78 if not DirectoryExists(pub_UnZipFileSaveDir) then //未压缩的文件保存路径 79 CreateDir(pub_UnZipFileSaveDir); 80 if not DirectoryExists(pub_ZipFileSaveDir) then //压缩包保存路径 81 CreateDir(pub_ZipFileSaveDir); 82 DeleteDirectory(pub_UnZipFileSaveDir); //每次打开先删除这两个目录下的所有文件 83 DeleteDirectory(pub_ZipFileSaveDir); 84 //此处要删除 上一次的txt和zip; 若改进为断点续传,可变更逻辑 85 86 try 87 inherited Create(True); 88 FreeOnTerminate := True; 89 FLogMsg:=LogMsgProc; 90 //FDeptID:=‘6‘; 91 pub_Critical := TCriticalSection.create; 92 ziper:=TVCLZip.Create(nil); 93 IdFTP:=TIdFTP.Create; 94 LogInfo(‘创建FTP上传线程成功!‘,true,true); 95 96 Resume; 97 except 98 on e:exception do 99 begin 100 FMessage:=‘创建FTP上传线程出错!‘#13+e.Message; 101 LogInfo(FMessage,true,true); 102 end; 103 end; 104 end; 105 106 procedure TFtpContentThd.Execute; 107 var 108 HasData: boolean; 109 begin 110 while not Terminated do 111 begin 112 113 DoPostContent(HasData); 114 115 if HasData then 116 Sleep(1000) 117 else 118 Sleep(pub_FtpExecInterval * 1000); //等待中 119 end; 120 end; 121 122 {Zip用法:Zip(压缩模式,压缩包大小,压缩或解压文件,解压或压缩目录,TVCLZip控件) 123 ZipMode为0:压缩;为1:解压缩 PackSize为0则不分包;否则为分包的大小 } 124 function TFtpContentThd.Zip(ZipMode, packSize: Integer; ZipFile, 125 UnzipDir: string): Boolean; 126 begin 127 if copy(UnzipDir,length(UnzipDir),1)=‘\‘then 128 UnzipDir:=copy(UnzipDir,1,length(UnzipDir)-1);//去除目录后的‘\‘ 129 try 130 ziper.DoAll:=False; //加此设置将对分包文件解压缩无效 131 ziper.OverwriteMode:=Always; //总是覆盖模式 132 133 if PackSize<>0then //0则压缩成一个文件,否则压成多文件 134 begin 135 ziper.MultiZipInfo.MultiMode:=mmBlocks; //设置分包模式 136 ziper.MultiZipInfo.SaveZipInfoOnFirstDisk:=True;//打包信息保存在第一文件中 137 ziper.MultiZipInfo.FirstBlockSize:=PackSize; //分包首文件大小 138 ziper.MultiZipInfo.BlockSize:=PackSize; //其他分包文件大小 139 end; 140 ziper.FilesList.Clear; 141 ziper.ZipName:=ZipFile; //获取压缩文件名 142 if ZipMode=0then //压缩 143 begin 144 ziper.FilesList.Add(UnzipDir+‘\*.txt‘); //添加压缩文件列表 设定为|*.txt文档,若需压缩全部可\*.* 145 //ziper. 146 Application.ProcessMessages; 147 ziper.Zip; 148 end else 149 begin 150 ziper.DestDir:=UnzipDir; //解压缩的目标目录 151 ziper.UnZip; //解压缩 152 end; 153 Result:=True; 154 except 155 on ex:exception do 156 begin 157 Result:=False; 158 FMessage := ‘文件解压缩异常‘#13 + ex.Message; 159 LogInfo(FMessage,True,True); 160 end; 161 end; 162 end; 163 164 {遍历当前FTP文件夹, 创建新目录或更改路径} 165 function TFtpContentThd.CreatFtpDir(UpLoadDir: string): Boolean; 166 var 167 CreatDirList: TStringList; 168 i,j,flag:Integer; 169 begin 170 CreatDirList:=TStringList.Create; 171 CreatDirList.Delimiter :=‘\‘; 172 CreatDirList.DelimitedText :=UpLoadDir; 173 for i := 0 to CreatDirList.Count - 1 do 174 begin 175 if CreatDirList[i]<>‘‘ then 176 begin 177 flag:=0; 178 IdFTP.List; 179 //ShowMessage(IntToStr(IdFTP.DirectoryListing.Count)); //默认uses idftplistParse异常;要添加IdFTPListParseWindowsNT,IdAllFTPListParsers单元 180 for j := 0 to IdFTP.DirectoryListing.Count-1 do //indy10要添加IdFTPListParseWindowsNT,IdAllFTPListParsers单元 181 begin //介绍:http://blog.sunshow.net/2007/07/tidftp-directorylisting-usage/ 182 if IdFTP.DirectoryListing.Items[j].ItemType = ditDirectory then //要添加单元IdFTPList 183 begin 184 if IdFTP.DirectoryListing.Items[j].FileName = CreatDirList[i] then 185 begin 186 flag:=1; //标志已经存在该目录 187 Break; 188 end; 189 end; 190 end; 191 if flag=0 then 192 IdFTP.MakeDir(CreatDirList[i]); //新创建文件夹 193 194 IdFTP.ChangeDir(CreatDirList[i]); //更改目录 195 end; 196 197 //***以下DirList内容有空格,IndexOf(CreatDirList[i])识别不了;也不严谨*** 198 { if CreatDirList[i]<>‘‘ then 199 begin 200 IdFTP.List(DirList,‘‘,True); 201 if (DirList.IndexOf(CreatDirList[i])=-1) then 202 begin 203 try 204 IdFTP.MakeDir(CreatDirList[i]); 205 except on ex:Exception do 206 LogInfo(‘添加目录名:‘+CreatDirList[i]+‘出错,原因:‘+ex.Message,True,True ); 207 end; 208 try 209 IdFTP.ChangeDir(CreatDirList[i]); 210 except on ex:Exception do 211 LogInfo(‘变更目录名:‘+CreatDirList[i]+‘出错,原因:‘+ex.Message,True,True ); 212 end; 213 end; 214 end; } 215 216 //***以下忽略异常,懒虫写法,*** 217 { try 218 IdFTP.ChangeDir(CreatDirList[i]); 219 except 220 IdFTP.MakeDir(CreatDirList[i]); 221 IdFTP.ChangeDir(CreatDirList[i]); 222 end;} 223 224 //***以下忽略异常,懒虫写法,*** 225 { try 226 IdFTP.MakeDir(CreatDirList[i]); 227 finally 228 IdFTP.ChangeDir(CreatDirList[i]); 229 end; } 230 231 end; 232 CreatDirList.Free; 233 Result :=True; 234 end; 235 236 destructor TFtpContentThd.Destroy; 237 begin 238 //inherited; //继承会产生异常 为什么?? 239 ziper.Free; 240 IdFTP.Free; 241 pub_Critical.Free; 242 try 243 LogInfo(‘FTP上传线程终止‘,False,true); 244 FtpContentThd.Terminate; 245 WaitForSingleObject(FtpContentThd.Handle, 500); 246 FtpContentThd := nil; 247 except on ex:Exception do 248 begin 249 250 end; 251 end; 252 end; 253 254 function TFtpContentThd.Get_Bak_Date: Boolean; 255 var 256 sql1 :string; 257 count :integer; 258 Now_Date :TDateTime; 259 begin 260 Result := True; 261 Now_Date := StrToDateTime(FormatDateTime(‘YYYY/MM/DD hh:mm:ss‘,Now())); 262 //获取时间段内的票面内容 263 Sql1 := ‘SELECT * FROM TICKET_CONTENT_BAK_DATE WHERE STATUS = 0‘; 264 try 265 try 266 with ClientDataModule.orqry1 do 267 begin 268 SQL.Clear; 269 SQL.Text := sql1; 270 Open; 271 First; 272 count := RecordCount; 273 if Count = 0 then 274 begin 275 //临时增加一条数据,否则程序无法进行 276 FMessage := ‘上传票面内容时,未找到相应上传区间。‘; 277 LogInfo(FMessage,True); 278 Result := False; 279 Exit; 280 end; 281 // 获取相关信息 282 FStart_Date := FieldByName(‘START_DATE‘).AsDateTime; // 获取起始时间 283 FEnd_Date := fieldByName(‘END_DATE‘).AsDateTime; // 获取结束时间 284 FNextDate := IncSecond(FEnd_Date,Pub_SecondInterval); 285 Close; 286 end; 287 Now_Date := IncMinute(Now_Date,-Pub_Before_Minitue); //只取Now()前5分钟的数据; 288 If FNextDate > Now_Date then 289 begin 290 Result := False; 291 end; 292 except on Ex:Exception do 293 begin 294 FMessage := ‘查找相应上传区间时,服务器断开或异常。‘; 295 LogInfo(FMessage,True); 296 Result := False; 297 end; 298 end; 299 finally 300 301 end; 302 end; 303 304 function TFtpContentThd.Get_ContentByDate(var HasData: boolean): Boolean; 305 var 306 sql1,s :string; 307 s_TID,s_CheckNo :string; 308 s_content,s_content_left,s_content_right :widestring; 309 Msg :string; 310 i : Integer; 311 begin 312 Result := True; 313 Msg := ‘查找票面内容,如下区间:‘; 314 Msg := Msg + Formatdatetime(‘YYYY-MM-DD hh:mm:ss‘,FStart_Date); 315 Msg := Msg + ‘ -- ‘; 316 Msg := Msg + Formatdatetime(‘YYYY-MM-DD hh:mm:ss‘,FEnd_Date); 317 LogInfo(Msg); 318 // 根据推送的时间段,从票据打印表中取出数据 319 Sql1 := ‘ SELECT A.TID,A.CHECK_NO,B.CONTENT FROM TICKET_PRINT_HISTORY A,TICKET_CONTENT B ‘ + 320 ‘ WHERE A.TID=B.TID ‘ + 321 ‘ AND A.PRINT_TIME >= TO_DATE(‘ + Quotedstr(DateTimeToStr(FStart_Date)) + ‘,‘ + Quotedstr(‘yyyy-mm-dd hh24:mi:ss‘) + ‘)‘ + 322 ‘ AND A.PRINT_TIME < TO_DATE(‘ + Quotedstr(DateTimeToStr(FEnd_Date)) + ‘,‘ + Quotedstr(‘yyyy-mm-dd hh24:mi:ss‘) + ‘)‘; 323 //测试语句 324 //sql1 := ‘SELECT TID,CHECK_NO FROM TICKET_PRINT_HISTORY WHERE TID >= 39332133 AND TID<=39334764‘; 325 326 try 327 try 328 with ClientDataModule.orqry1 do 329 begin 330 try 331 sql.Clear; 332 SQL.Text := sql1; 333 Open; 334 First; 335 FCount := RecordCount; 336 if FCount > 0 then 337 begin 338 HasData := True; 339 LogInfo(‘开始解析票面内容。总数为: ‘ + IntToStr(FCount) + ‘条。‘); 340 end 341 else 342 begin 343 HasData := False; 344 FMessage := ‘查找区间票面内容为空。‘; 345 LogInfo(FMessage); 346 Result := True; 347 Exit; 348 end; 349 while not Eof do 350 begin 351 Try 352 s_TID := FieldByName(‘TID‘).asstring; 353 LogInfo(‘解析票面内容。票ID为:‘ + s_TID,False,True); //不需要写日志吧 354 FContent := Trim(FieldByName(‘CONTENT‘).Asstring); 355 //FContent := Trim(FieldByName(‘CHECK_NO‘).Asstring); //ss测试语句 356 pub_Critical.Enter; 357 try 358 WriteLog(pub_UnZipFileSaveDir+‘\‘ +s_TID+ ‘.Txt‘,FContent,True); //若存在该文件,覆盖模式 359 finally 360 pub_Critical.Leave; 361 end; 362 Next; 363 except on Ex:Exception do 364 begin 365 FMessage := ‘解析单张票面内容时,出现异常。‘ + Ex.Message; 366 LogInfo(FMessage,True); 367 Result := False; 368 Exit; 369 end; 370 end; 371 end; 372 Close; 373 Except on Ex:Exception do 374 begin 375 Close; 376 FMessage := ‘查找区间内票面内容时,服务器断开或异常。‘ + Ex.Message; 377 LogInfo(FMessage,True); 378 //获取数据时出现异常 379 Result := False; 380 end; 381 end; 382 end; 383 Except on Ex:Exception do 384 begin 385 FMessage := ‘查找区间内票面内容时,服务器断开或异常。‘ + Ex.Message; 386 LogInfo(FMessage,True); 387 //获取数据时出现异常 388 Result := False; 389 end; 390 end; 391 finally 392 end; 393 end; 394 395 procedure TFtpContentThd.DoPostContent(var HasData: boolean); 396 begin 397 HasData := False; 398 try 399 //1、从数据库取得指定区间的数据,保存为多个txt, 400 //2、当前文件夹的*.txt全部保存为zip 401 //3、ftp上传到服务器 402 403 LogInfo(‘开始取区间‘); 404 if not Get_Bak_Date then Exit; 405 LogInfo(‘开始取区间内票面内容‘); 406 //ss -------测试 407 //FStart_Date:=Now(); 408 //FEnd_Date:=Now(); 409 if not Get_ContentByDate(HasData) then Exit; 410 411 DateTimeToString(Filename,‘YYYYMMDD-HHMMSS‘,FStart_Date); //压缩包名称,以区间开始时间命名 412 Filename:=Filename+‘.zip‘; 413 414 LogInfo(‘执行压缩‘); 415 if not Zip(0,0,pub_ZipFileSaveDir+‘\‘+Filename,pub_UnZipFileSaveDir) then //将abc.zip解压到路径,若不存在会自动创建目录的。 416 begin //压缩时,若路径不存在,是否会创建; 417 exit; 418 end; 419 420 LogInfo(‘提交票面内容压缩包到文件服务器‘); 421 DateTimeToString(ZipUpLoadDir,‘YYYY\MM\DD\HH‘,Now); //压缩包上传路径 422 if not UpLoad_Content_Zip then Exit; 423 LogInfo(‘更新提交状态‘); 424 if not Update_Content_Bak_Date then Exit; 425 LogInfo(‘执行下一批数据‘); 426 finally 427 428 end; 429 end; 430 431 function TFtpContentThd.UpLoad_Content_Zip: Boolean; 432 begin 433 //发送 434 Result:=False; 435 with IdFTP do 436 begin 437 if not Connected then 438 begin 439 Username:=pub_FtpUsername; 440 Password:=pub_FtpPassword; 441 try 442 Connect(pub_FtpHost,pub_FtpPort); 443 except 444 on e:exception do 445 begin 446 FMessage:=‘连接FTP服务器出错!‘#13+e.Message; 447 LogInfo(FMessage,true,true); 448 Exit; 449 end; 450 end; 451 end; 452 if Connected then 453 begin 454 if ZipUpLoadDirTemp<>ZipUpLoadDir then //上传保存的路径改变,则创建新目录或更改路径。 455 begin 456 ChangeDir(pub_ZipUpLoadRtDir); //先回到设定的根目录 457 CreatFtpDir(ZipUpLoadDir); //遍历当前FTP文件夹, 创建新目录或更改路径 458 end; 459 try 460 Put(pub_ZipFileSaveDir+‘\‘+Filename,Filename); 461 462 deletefile(PChar(pub_ZipFileSaveDir+‘\‘+Filename)); //删除已上传的文件 463 DeleteDirectory(pub_UnZipFileSaveDir); //删除已经上传的文件夹的所有txt 464 except 465 on e:exception do 466 begin 467 FMessage:=‘文件上传FTP服务器出错!‘#13+e.Message; 468 LogInfo(FMessage,true,true); 469 Exit; 470 end; 471 end; 472 end; 473 end; 474 ZipUpLoadDirTemp:=ZipUpLoadDir; 475 Result:=True; 476 end; 477 478 function TFtpContentThd.Update_Content_Bak_Date: Boolean; 479 var 480 sql1,sql2 : string; 481 begin 482 Result := True; 483 try 484 // 如果上面对数据进行处理出现异常时,则退出本次上传 485 // 全部数据上传成功,则进行状态重置 486 Sql1 := ‘BEGIN UPDATE TICKET_CONTENT_BAK_DATE SET STATUS=1,POST_DATE=SYSDATE, ‘ + 487 ‘ POST_COUNT=‘ + Quotedstr(IntTostr(FCount)) + 488 ‘ WHERE STATUS = 0;‘; 489 490 // 插入下一条上传时间段 491 sql2 := ‘ INSERT INTO TICKET_CONTENT_BAK_DATE (ID,START_DATE,END_DATE,POST_COUNT,POST_DATE,STATUS) ‘ + 492 ‘ VALUES(SEQ_CONTENT_BAK_DATE.Nextval,TO_DATE(‘+ Quotedstr(Formatdatetime(‘YYYY-MM-DD hh:mm:ss‘,FEnd_Date)) + 493 ‘,‘ + QuotedStr(‘yyyy-mm-dd hh24:mi:ss‘) + ‘),TO_DATE(‘ + Quotedstr(Formatdatetime(‘YYYY-MM-DD hh:mm:ss‘,FNextDate)) + 494 ‘,‘ + QuotedStr(‘yyyy-mm-dd hh24:mi:ss‘) + ‘),0,SYSDATE,0);‘ + 495 ‘ COMMIT; END;‘ ; 496 ClientDataModule.orqry1.SQL.Clear; 497 ClientDataModule.orqry1.SQL.Text := sql1 + sql2; 498 ClientDataModule.orqry1.Execute; 499 ClientDataModule.orqry1.Close; 500 // 501 //LogInfo(‘建立下一次上传区间‘); 502 except on ex:exception do 503 begin 504 FMessage := ‘更新上传状态时,服务器断开或异常。‘ + Ex.Message; 505 LogInfo(FMessage,True); 506 Result := False; 507 end; 508 end; 509 end; 510 511 {循环删除整个目录下的所有文件包括文件夹} 512 function TFtpContentThd.DeleteDirectory(NowPath: string): Boolean; 513 var 514 search: TSearchRec; 515 ret: integer; 516 key: string; 517 begin 518 Result:=False; 519 if NowPath[Length(NowPath)] <> ‘\‘ then 520 NowPath := NowPath + ‘\‘; 521 key := NowPath + ‘*.*‘; 522 ret := findFirst(key, faanyfile, search); 523 while ret = 0 do 524 begin 525 if ((search.Attr and fadirectory) = fadirectory) then 526 begin 527 if (search.Name <> ‘.‘) and (search.name <> ‘..‘) then 528 begin 529 DeleteDirectory(NowPath + search.name); 530 removedir(NowPath + search.name); //如果需要删除文件夹则添加 531 end; 532 end 533 else 534 begin 535 if ((search.Attr and fadirectory) <> fadirectory) then 536 begin 537 deletefile(PAnsiChar(NowPath + search.name)); 538 539 end; 540 end; 541 ret := FindNext(search); 542 end; 543 SysUtils.FindClose(search); 544 //FindClose(search.FindHandle); 545 //FindClose(search); //发现在线程里面不能用这,只能用上面的句柄 546 //removedir(NowPath); //如果需要删除最外层文件夹则添加 547 result := True; 548 end; 549 procedure TFtpContentThd.LogInfo(AMsg: string; const blnIsErrorMsg, 550 BoolSaveToFile: Boolean); 551 begin 552 pub_Critical.Enter; 553 try 554 FLogMsg(AMsg,blnIsErrorMsg,BoolSaveToFile); 555 finally 556 pub_Critical.Leave; 557 end; 558 end; 559 560 initialization 561 // 562 finalization 563 // 564 end.
代码
1 procedure TFrmFTP_ZIP.btnBreUpLoadClick(Sender: TObject); 2 var 3 tStream: TFileStream; 4 Size1:Integer; 5 begin 6 if IdFTP1.Connected then 7 begin 8 if not UploadOpenDialog1.Execute then 9 Exit; 10 tStream:=TFileStream.Create(UploadOpenDialog1.FileName,fmOpenRead ); 11 try 12 Size1 :=IdFTP1.Size(ExtractFileName(UploadOpenDialog1.FileName)); 13 if Size1 >0 then //这样判断文件是否存在 是错误的。 14 begin 15 case MessageDlg(‘文件已经存在,是否续传?‘, mtConfirmation, mbYesNoCancel, 0) of 16 mrYes: 17 begin 18 tStream.Position:=Size1; 19 //tStream.Seek(IdFTP1.Size(‘Delphi大量pdf资料非扫描档1.zip‘),0) ; //也可以。 20 IdFTP1.Put(tStream,ExtractFileName(UploadOpenDialog1.FileName),true); //续传 21 end; 22 mrNo: 23 begin 24 IdFTP1.Put(tStream,ExtractFileName(UploadOpenDialog1.FileName),False); //重新传 25 end; 26 mrCancel: Exit; //取消 27 end; 28 end 29 else 30 IdFTP1.Put(tStream,ExtractFileName(UploadOpenDialog1.FileName),False); 31 32 { tStream.Position:=IdFTP1.Size(‘Delphi大量pdf资料非扫描档1.zip‘); //当前路径的指定文件 33 //tStream.Seek(IdFTP1.Size(‘Delphi大量pdf资料非扫描档1.zip‘),0) ; //也可以。 34 IdFTP1.Put(tStream,‘Delphi大量pdf资料非扫描档1.zip‘,true); } 35 36 finally 37 tStream.Free; 38 end; 39 end 40 else 41 ShowMessage(‘Ftp未连接‘); 42 end; 43 44 procedure TFrmFTP_ZIP.btnBreDownLoadClick(Sender: TObject); 45 begin 46 if IdFTP1.Connected then 47 begin 48 if FileExists(‘Delphi大量pdf资料非扫描档1.zip‘) then 49 begin 50 case MessageDlg(‘文件已经存在,是否续传?‘, mtConfirmation, mbYesNoCancel, 0) of 51 mrYes: FtpDownLoad( ‘Delphi大量pdf资料非扫描档1.zip‘, True); //续传 52 mrNo: FtpDownLoad( ‘Delphi大量pdf资料非扫描档1.zip‘, False); //覆盖 53 mrCancel: Exit; //取消 54 end; 55 end 56 else 57 FtpDownLoad( ‘Delphi大量pdf资料非扫描档1.zip‘, False); //建立新文件下载 58 end 59 else 60 ShowMessage(‘Ftp未连接‘); 61 end;
断点上传和断点下载代码
时间: 2024-11-09 00:32:04