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,轉發請保留這個地址,謝謝