Delphi组件Indy 10中修正IdFTP不能续传问题
2007-12-07 09:35
381 查看
原文: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中均存在同样问题
提出问题:
在使用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中均存在同样问题
相关文章推荐
- Delphi组件indy 10中IdTCPServer修正及SSL使用心得
- 解决FTP客户端文件断点续传过程中服务器无法知晓文件总大小的问题
- navicat不能访问虚拟机myslq的问题修正
- discuz,ucenter,uchome修改密码 phpcms不能登陆的问题修正
- Delphi:INDY组件IDFTP/IDHTTP的connecttimeout超时问题
- mysqlId 不能自启的问题(错误代号2003)
- 解决vmware10在linux内核升级后不能启动的问题VMWare Kernel Module Updater
- iOS 10 使用相机及相簿闪退的问题修正
- 开启LINUX防火墙后,FTP PASV不能正常登录问题
- 【安卓学习之第三方库】库的使用3-不能访问资源ID问题
- c#扩展SPRING,配置里有不存在的业务系统xml导致不能启动问题,把配置文件里有重复的服务ID找出来并写入到日志
- extjs中关于数据库id不能重复的问题
- 安装了java10,但安装SQLServer2016和2017破解myeclipse不能启动的问题
- AIX 不能创建 高权限ID 的 问题
- [修正] iOS 10 使用相机及相簿闪退的问题修正
- Solaris 10下有趣的FTP错误--ROOT不能访问FTP
- 解决ubuntu下root用户 不能ftp登陆的问题
- Xcode8(iOS 10)快速注释不能用的问题
- window ftp上传zip文件,linux不能用unzip解压问题