Delphi组件Indy 10中修正IdFTP不能续传问题

原文:http://blog.dream4dev.com/article.asp?id=144

提出问题:
在使用IdFTP组件下载文件时候,发现不能续传文件
     procedure Get(const ASourceFile: string; ADest: TIdStream; AResume: Boolean = false); overload;
     procedure Get(const ASourceFile, ADestFile: string; const ACanOverwrite: boolean = false; AResume: Boolean = false); overload;

查看源代码(IdFTP.pas),发现:

procedure TIdFTP.Get(const ASourceFile, ADestFile: string; const ACanOverwrite: boolean = False;
   AResume: Boolean = false);
var
   LDestStream: TIdStream;
begin
   .....
   try
     Get(ASourceFile, LDestStream, AResume);//---->主要用到TIdFTP.Get(const ASourceFile: string; ADest: TIdStream; AResume: Boolean = False);
   finally
     Sys.FreeAndNil(LDestStream);
   end;
end;

procedure TIdFTP.Get(const ASourceFile: 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 ASourceFile: 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 ASourceFile: 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 Dream4Drv
     ADest.Position := ADest.Size
   else
     ADest.Position := 0;
   InternalGet('RETR ' + ASourceFile, ADest, AResume);
end;
Delphi7~Delphi2007组件Indy 10的IdFTP中均存在同样问题

 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值