您的位置:首页 > 编程语言 > PHP开发

5、利用控件TVCLZip和TIdFTP压缩文件并上传到FTP的线程单元pas 改进版

2015-04-10 16:27 537 查看
用到临界区 保护写日志的函数;

递归函数 删除目录下的所有文件;

循环创建或判断FTP的目录;

可改进的地方:循环压缩深层次目录的所以文件; 实现断点续传,或断点下载;

procedure TFrmFTP_ZIP.btnBreUpLoadClick(Sender: TObject);
var
tStream: TFileStream;
Size1:Integer;
begin
if IdFTP1.Connected then
begin
if not UploadOpenDialog1.Execute then
Exit;
tStream:=TFileStream.Create(UploadOpenDialog1.FileName,fmOpenRead );
try
Size1 :=IdFTP1.Size(ExtractFileName(UploadOpenDialog1.FileName));
if Size1 >0 then   //这样判断文件是否存在 是错误的。
begin
case MessageDlg('文件已经存在,是否续传?', mtConfirmation, mbYesNoCancel, 0) of
mrYes:
begin
tStream.Position:=Size1;
//tStream.Seek(IdFTP1.Size('Delphi大量pdf资料非扫描档1.zip'),0) ; //也可以。
IdFTP1.Put(tStream,ExtractFileName(UploadOpenDialog1.FileName),true); //续传
end;
mrNo:
begin
IdFTP1.Put(tStream,ExtractFileName(UploadOpenDialog1.FileName),False); //重新传
end;
mrCancel: Exit; //取消
end;
end
else
IdFTP1.Put(tStream,ExtractFileName(UploadOpenDialog1.FileName),False);

{ tStream.Position:=IdFTP1.Size('Delphi大量pdf资料非扫描档1.zip'); //当前路径的指定文件
//tStream.Seek(IdFTP1.Size('Delphi大量pdf资料非扫描档1.zip'),0) ; //也可以。
IdFTP1.Put(tStream,'Delphi大量pdf资料非扫描档1.zip',true); }

finally
tStream.Free;
end;
end
else
ShowMessage('Ftp未连接');
end;

procedure TFrmFTP_ZIP.btnBreDownLoadClick(Sender: TObject);
begin
if IdFTP1.Connected then
begin
if FileExists('Delphi大量pdf资料非扫描档1.zip') then
begin
case MessageDlg('文件已经存在,是否续传?', mtConfirmation, mbYesNoCancel, 0) of
mrYes: FtpDownLoad( 'Delphi大量pdf资料非扫描档1.zip', True); //续传
mrNo: FtpDownLoad( 'Delphi大量pdf资料非扫描档1.zip', False); //覆盖
mrCancel: Exit; //取消
end;
end
else
FtpDownLoad( 'Delphi大量pdf资料非扫描档1.zip', False); //建立新文件下载
end
else
ShowMessage('Ftp未连接');
end;


断点上传和断点下载代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: