Indy文件断点续传代码

寵の児 提交于 2020-02-05 02:30:40

 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.dfwlt.com/forum.php?mod=viewthread&tid=56&extra=page%3D1,转发请保留这个地址,谢谢

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!