我程序加了续传功能,每次中途关掉程序下次可以续传,下载的文件也是完好的,但是网络中断后程序未退出再续传的文件却是损坏了的
附上代码
if FileExists(aFile) then //建立文件流
tStream := TFileStream.Create(aFile, fmOpenWrite)
else
tStream := TFileStream.Create(aFile, fmCreate);
tStream.Position := tStream.Size;
DownIdFTP.Get(aFile, tStream, true);
附上代码
if FileExists(aFile) then //建立文件流
tStream := TFileStream.Create(aFile, fmOpenWrite)
else
tStream := TFileStream.Create(aFile, fmCreate);
tStream.Position := tStream.Size;
DownIdFTP.Get(aFile, tStream, true);
var
tStream: TFileStream;
sName, sPass, sHost, sPort, sDir: string;
begin //ftp方式下载
if FileExists(aFile) then //建立文件流
tStream := TFileStream.Create(aFile, fmOpenWrite) else
tStream := TFileStream.Create(aFile, fmCreate); GetFTPParams(aURL, sName, sPass, sHost, sPort, sDir);
with IdFTP1 do
try
if Connected then Disconnect; //重新连接
Username := sName;
Password := sPass;
Host := sHost;
Port := StrToInt(sPort);
Connect;
except
exit;
end; IdFTP1.ChangeDir(sDir); //改变目录
BytesToTransfer := IdFTP1.Size(aFile);
try
if bResume then //续传
begin
tStream.Position := tStream.Size;
IdFTP1.Get(aFile, tStream, True);
end else
begin
IdFTP1.Get(aFile, tStream, False);
end;
finally
tStream.Free;
end;
end;