M
maikee1978
Unregistered / Unconfirmed
GUEST, unregistred user!
这是我用的一个用来下载一个目录的函数,下载单个文件很少出问题,少数几个也很少出问题,多个目录多个文件后有时也没问题,有时却卡死(7成),请帮忙看下,先谢,后再谢!!特别是下载一个Delphi包vclx60.bpl时必卡
function TfrmAPL_U.DownAllFile(LocalFolder, HostFolder: widestring):boolean;
var
FileLst:tstrings;
iCount,jCount:integer;
FName:widestring;
begin
Result:=false;
FileLst:=TStringlist.Create;
if not FTPClient1.Connected then FtpClient1.Connect;
if FTPClient1.Connected then
try
FTPClient1.HostFileName:=HostFolder;
if not DirectoryExists(LocalFolder) then
mkdir(LocalFolder);
//DeleteFile(ExtractFilepath(paramstr(0))+'TMPFILELST.TXT');
FtpClient1.LocalFileName:=ExtractFilepath(paramstr(0))+'TMPFILELST.TXT';
FtpClient1.DisplayFileFlag:=false;
if FTpClient1.Connected then //关于这一段,我原本没用,但是多次Dir后卡住
begin
FtpClient1.AbortXfer;
FtpClient1.Quit;
end;
if not FtpClient1.connected then FtpClient1.connect;
FtpClient1.Dir;
FileLst.LoadFromFile(ExtractFilepath(paramstr(0))+'TMPFILELST.TXT');
Geting:=false;
for iCount:=0 to Filelst.Count-1 do
if trim(FileLst[iCount])<>'' then
begin
if IsDirectory(Filelst[iCount],FName) then
DownAllFile(LocalFolder+'/'+FName, HostFolder+'/'+FName)
else
begin
FtpClient1.HostFileName:=HostFolder+'/'+FName;
FtpClient1.LocalFileName:=LocalFolder+'/'+FName;
FtpClient1.AbortXfer;
FtpClient1.Size;
ProgD.Max:=DFSize;
if DFSize>1024*1024 then
lblDSize.Caption:=FormatFloat('#.00',DFSize/1024/1024)+'MB'
else if DFSize>1024 then
lblDSize.Caption:=FormatFloat('#.00',DFSize/1024)+'KB'
else
lblDSize.Caption:=inttostr(DFSize)+'Bytes';
lblDFinfo.Caption:='下载:'+FName+'文件';
// Err:=true;
// JCount:=0;
//while Err and (JCount<10) do //取消注释后这段我用了一个出错循环下载措施
//begin
// Err:=false;
// JCount:=JCount+1;
// Geting:=true;
// tmeCount:=0;
// timer1.Enabled:=true;
if FtpClient1.Connected then //这段原因也是因为老卡,所以我就每下一个文件就重断开连一次
begin
FtpClient1.AbortXfer;
FtpClient1.Quit;
end;
if not FtpClient1.Connected then FtpClient1.Connect;
FtpClient1.Get;
FtpClient1.RestGet;
FtpClient1.AbortXfer;
Geting:=false;
end;
ProgTotal.Position:=ProgTotal.Position+DFSize;
if progTotal.Position>1024*1024 then
lblTotal.Caption:=FormatFloat('#.00',ProgTotal.position/1024/1024)+'MB'
else if ProgTotal.Position>1024 then
lblTotal.Caption:=FormatFloat('#.00',ProgTotal.position/1024)+'KB'
else
lblTotal.Caption:=inttostr(ProgTotal.position);
end;
end;
finally
Filelst.Free;
end;
Result:=true;
end;
请教各位兄弟姐妹们,给指教指教问题出在哪吧!都困扰了我好几个月了。
function TfrmAPL_U.DownAllFile(LocalFolder, HostFolder: widestring):boolean;
var
FileLst:tstrings;
iCount,jCount:integer;
FName:widestring;
begin
Result:=false;
FileLst:=TStringlist.Create;
if not FTPClient1.Connected then FtpClient1.Connect;
if FTPClient1.Connected then
try
FTPClient1.HostFileName:=HostFolder;
if not DirectoryExists(LocalFolder) then
mkdir(LocalFolder);
//DeleteFile(ExtractFilepath(paramstr(0))+'TMPFILELST.TXT');
FtpClient1.LocalFileName:=ExtractFilepath(paramstr(0))+'TMPFILELST.TXT';
FtpClient1.DisplayFileFlag:=false;
if FTpClient1.Connected then //关于这一段,我原本没用,但是多次Dir后卡住
begin
FtpClient1.AbortXfer;
FtpClient1.Quit;
end;
if not FtpClient1.connected then FtpClient1.connect;
FtpClient1.Dir;
FileLst.LoadFromFile(ExtractFilepath(paramstr(0))+'TMPFILELST.TXT');
Geting:=false;
for iCount:=0 to Filelst.Count-1 do
if trim(FileLst[iCount])<>'' then
begin
if IsDirectory(Filelst[iCount],FName) then
DownAllFile(LocalFolder+'/'+FName, HostFolder+'/'+FName)
else
begin
FtpClient1.HostFileName:=HostFolder+'/'+FName;
FtpClient1.LocalFileName:=LocalFolder+'/'+FName;
FtpClient1.AbortXfer;
FtpClient1.Size;
ProgD.Max:=DFSize;
if DFSize>1024*1024 then
lblDSize.Caption:=FormatFloat('#.00',DFSize/1024/1024)+'MB'
else if DFSize>1024 then
lblDSize.Caption:=FormatFloat('#.00',DFSize/1024)+'KB'
else
lblDSize.Caption:=inttostr(DFSize)+'Bytes';
lblDFinfo.Caption:='下载:'+FName+'文件';
// Err:=true;
// JCount:=0;
//while Err and (JCount<10) do //取消注释后这段我用了一个出错循环下载措施
//begin
// Err:=false;
// JCount:=JCount+1;
// Geting:=true;
// tmeCount:=0;
// timer1.Enabled:=true;
if FtpClient1.Connected then //这段原因也是因为老卡,所以我就每下一个文件就重断开连一次
begin
FtpClient1.AbortXfer;
FtpClient1.Quit;
end;
if not FtpClient1.Connected then FtpClient1.Connect;
FtpClient1.Get;
FtpClient1.RestGet;
FtpClient1.AbortXfer;
Geting:=false;
end;
ProgTotal.Position:=ProgTotal.Position+DFSize;
if progTotal.Position>1024*1024 then
lblTotal.Caption:=FormatFloat('#.00',ProgTotal.position/1024/1024)+'MB'
else if ProgTotal.Position>1024 then
lblTotal.Caption:=FormatFloat('#.00',ProgTotal.position/1024)+'KB'
else
lblTotal.Caption:=inttostr(ProgTotal.position);
end;
end;
finally
Filelst.Free;
end;
Result:=true;
end;
请教各位兄弟姐妹们,给指教指教问题出在哪吧!都困扰了我好几个月了。