千家信息网

Indy文件断点续传代码

发表于:2024-11-20 作者:千家信息网编辑
千家信息网最后更新 2024年11月20日,function TFrmFileManageCard.UpLoadFileBreak(SourseFileName,DestFileName: String): Integer; var upsiz
千家信息网最后更新 2024年11月20日Indy文件断点续传代码

function TFrmFileManageCard.UpLoadFileBreak(SourseFileName,

DestFileName: String): Integer; var upsize:int64; IDFTP:TidFtp; LSourceStream: TFileStream; LSourceStreamA:TMemoryStream; begin Result:=-1; if Application.MessageBox('文件上传失败,是否断点续传?','提示!',MB_YESNO)<>ID_YES then begin Exit; end; try try IDFTP:=TidFtp.Create(Nil); LSourceStream := TFileStream.Create(SourseFileName, fmOpenRead or fmShareDenyNone); IdFTP.Abort; IdFTP.Host:=FTPHTTPControl.CUR_C_FTPSERVER; IdFTP.Port:=FTPHTTPControl.CUR_I_FTPPORT; IdFTP.Username:=FTPHTTPControl.CUR_C_FTPUSER; IdFTP.Password:=FTPHTTPControl.CUR_C_FTPPWS; IdFTP.Connect(); try IdFTP.ChangeDir(AMShare.CurP_MMroomData.C_MMROOM_ID); except IdFTP.MakeDir(AMShare.CurP_MMroomData.C_MMROOM_ID); IdFTP.ChangeDir(AMShare.CurP_MMroomData.C_MMROOM_ID); end; try IdFTP.ChangeDir(Copy(ExtractFIleName(DestFileName), 1, 1)); except IdFTP.MakeDir(Copy(ExtractFIleName(DestFileName), 1, 1)); IdFTP.ChangeDir(Copy(ExtractFIleName(DestFileName), 1, 1)); end; try IdFTP.ChangeDir(Copy(ExtractFIleName(DestFileName), 2, 1)); except IdFTP.MakeDir(Copy(ExtractFIleName(DestFileName), 2, 1)); IdFTP.ChangeDir(Copy(ExtractFIleName(DestFileName), 2, 1)); end; upsize:=IdFTP.Size(ExtractFIleName(DestFileName)); LSourceStream.Position:=upsize; IdFTP.Passive:=True; IdFTP.Put(SourseFileName,ExtractFIleName(DestFileName),true); IdFTP.Disconnect; Result:=0; except end; finally FreeANdNil(IDFTP); FreeANdNil(LSourceStream); end; //如果上传失败,继续询问 if Result<>0 then begin //如果失败,继续断点续传 UpLoadFileBreak(SourseFileName,DestFileName); end; end;

本文地址:http://www.xszlo.com/article/2012-09-24/7458.html,转发请保留这个地址,谢谢

0