载入中...
 
 
Delphi组件Indy 10中修正IdFTP不能续传问题
[ 2007-12-20 16:37:00 | By: blogger ]
 
提出问题:
在使用IdFTP组件下载文件时候,发现不能续传文件
    procedure Get(const ASource string; ADest: TIdStream; AResume: Boolean = false); overload;
    procedure Get(const ASourceFile, ADest string; const ACanOverwrite: boolean = false; AResume: Boolean = false); overload;

查看源代码(IdFTP.pas),发现:
procedure TIdFTP.Get(const ASourceFile, ADest string; const ACanOverwrite: boolean = False;
  AResume: Boolean = false);
var
  LDestStream: TIdStream;
begin
  .....
  try
    Get(ASourceFile, LDestStream, AResume);//---->主要用到TIdFTP.Get(const ASource string; ADest: TIdStream; AResume: Boolean = False);
  finally
    Sys.FreeAndNil(LDestStream);
  end;
end;

procedure TIdFTP.Get(const ASource string; ADest: TIdStream; AResume: Boolean = False);
begin
  //for SSL FXP, we have to do it here because InternalGet is used by the LIST command
  //where SSCN is ignored.
  ClearSSCN;
  AResume := AResume and CanResume;
  ADest.Position := 0;//---->问题出在这句,每次都重置了。
  InternalGet('RETR ' + ASourceFile, ADest, AResume);
end;

为什么这句会使控件不能续传,因为续传命令代码:
procedure InternalGet(const ACommand: string; ADest: TIdStream; AResume: Boolean = false);
.......
          if AResume then begin
            Self.SendCmd('REST ' + Sys.IntToStr(ADest.Position), [350]);   {do not localize}
          end;

解决办法:
修改过程procedure TIdFTP.Get(const ASource string; ADest: TIdStream; AResume: Boolean = False);
只要Remark了  ADest.Position := 0;问题就能解决
但这样做,也有后遗症,每次执行Get之前,还需要指定Position,否则容易出问题(打开Stream时候,默认Posotion为0)

完美解决:
把ADest.Position := 0;
修改为ADest.Position := ADest.Size;

完整代码:
procedure TIdFTP.Get(const ASource string; ADest: TIdStream; AResume: Boolean = False);
begin
  //for SSL FXP, we have to do it here because InternalGet is used by the LIST command
  //where SSCN is ignored.
  ClearSSCN;
  AResume := AResume and CanResume;
  if AResume then//Fix by Dream4Dev
    ADest.Position := ADest.Size
  else
    ADest.Position := 0;
  InternalGet('RETR ' + ASourceFile, ADest, AResume);
end;

Delphi7~Delphi2007组件Indy 10的IdFTP中均存在同样问题
 
 
发表评论:
载入中...

载入中...
时 间 记 忆
载入中...
最 新 评 论
载入中...
专 题 分 类
载入中...
最 新 日 志
载入中...
最 新 留 言
载入中...
搜 索
用 户 登 录
载入中...
友 情 连 接
博 客 信 息
载入中...


Powered by Oblog.