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,转发请保留这个地址,谢谢
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/opensource/194612.html