idFTP 上传续传功能的实现/ 有哪位高手知道怎样实现idFtp上传续传方法. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 断点续传首先要取决于FTP站点是否支持断点续传的功能。idFtp有个CanResume属性,可以检测站点是否支持断点续传。idFtp的Get/Set方法中有个参数AResume,用来控制上传/下载文件时是否支持断点续传。如果没有AResume参数,那可能是idFTP版本较早。我用的是idFTP V9.0是有AResume参数的。 //上传文件处理过程。procedure TFTPModel.Upload;function RemoveExt(const AFileName: String): String;{ Helper function to removes the extension from a file name. }begin if Pos('.', AFileName) <> 0 then Result := Copy(AFileName, 1, Pos('.', AFileName)-1) else Result := AFileName;end;var FileName : string; sZipFileName:string; Item : TListItem; QueueItem : TListItem;begin //没有登录文件服务器,不进行上传处理。 if not FFTPClient.Connected Then begin Application.MessageBox('没有登录文件传输服务器,不能上传文件',SysHintMsgTitle); Exit; end; //没有选中目录 if FLVLocalFile.Selected = nil then Exit; Item := FLVLocalFile.Selected; FLVQueue.Clear; while Item <> nil do begin //这里加了约束,是文件夹的话,不加到上传队列, //也就是说不支持文件夹的上传。 if Item.SubItems[0]<>'文件夹' then begin QueueItem := FLVQueue.Items.Add; QueueItem.Caption := Item.Caption; QueueItem.SubItems.Add(FLocaLPath); QueueItem.SubItems.Add(Item.SubItems[1]); QueueItem.SubItems.Add('->'); QueueItem.SubItems.Add(''); QueueItem.SubItems.Add(FRemotePath); end; Item:=FLVLocalFile.GetNextItem(Item,sdAll, [isSelected]); end; FLVQueue.Refresh; { LViewLocalFile.Enabled:=false; LViewRemoteFile.Enabled:=False; RemoteUpDir.Enabled:=false; } //上传文件。表示正在上传 FLoadOption:=loUpLoad; try while FLVQueue.Items.Count > 0 do begin FileName:=FLVQueue.Items[0].Caption; FLVQueue.Items[0].SubItems[3]:='正在上传'; FLVQueue.Refresh; //本来上传语句是下面这句,由于,怕出现 中断上传 的问题,也就是服务端有该目录, //所以注释这句。采用下面这句,追加上传。 // 2005-3-11 中午,覆盖模式。 //FFTPClient.Put(FLocalPath+'\'+FileName, FileName); //追加模式,再文件后面追加内容。 {//断点传输解决方案。 问: 请问idftp能否做到断点续传,下载倒是蛮好实现的,但是不知道上传要怎么做到断点续传??? 且如果文件名未改变,但文件改变了,下载(断点续传)时是否会自动判断??? 答: 上传断点续传原理是这样的: 假设有个 file.zip 传了50%断掉后 先 resumepoint:=idftp1.size('file.zip'); 再 打开 本地 file.zip 到fileStream,seek 到 resumepoint; idftp1.Quote('REST '+floattostr(resumepoint)); idftp1.put(fileStream,Orderputfilename,true); 关键一点是要修改indy 的源代码 indy是用sendcmd 'APPE' 方式续上传的,要改为sendcmd 'STOR' --- 注:本方法在serv-u 5.0 ,indy 9.0.4上测试通过 } //压缩文件 {sZipFileName:=RemoveExt(FileName)+'.Zip'; FVCLZip.FilesList.Clear; FVCLZip.FilesList.Add(FLocalPath+'\'+FileName); FVCLZip.ZipName:=FLocalPath+'\'+sZipFileName; FVCLZip.Zip;} //以前的代码注释于 2005年4月14日 (* 用Size方法就可以!返回 550就文件不存在 213就存在 *) //远程存在,则删除 if FFTPClient.Size(FRemotePath+sZipFileName)>-1 then begin FFTPClient.Delete(FRemotePath+sZipFileName); end; //上传文件函数 FFTPClient.Put(FLocalPath+'\'+sZipFileName, sZipFileName,True); //删除本地临时文件 DeleteFile(PChar(FLocalPath+'\'+sZipFileName)); //更新远程路径。 //********* RemoteChangeDir; FLVQueue.items[0].Delete; FLVQueue.Refresh;; end; FLoadOption:=loNone; except FLVQueue.Items[0].SubItems[3]:='错误'; FLoadOption:=loNone; end;end; 我用的是 9.0.10,delphi 7 自带的,上传还是不可以续传! 寻求版主,关于全局快捷键 一些特殊按键 关于注册表的操作! 串口编程? 一段读取硬盘序列号的代码。可以翻译成C++吗? 实现网络数据传送,高手进来!! 刚加入,没带什么礼物,向大家推荐一个vc编程站点吧! 关于排序! 送高手100分,关于AdvancedCustomDrawItem的问题! 报表问题! 那里有好一些的关于数据库的源程序下载,多谢!!!!! 请教:怎么把对象转存到byte()数组? 请教大家在SQL中的日期处理问题,在人事表怎样用SQL语句更新全部员工的的工龄和年龄?
idFtp有个CanResume属性,可以检测站点是否支持断点续传。
idFtp的Get/Set方法中有个参数AResume,用来控制上传/下载文件时是否支持断点续传。
如果没有AResume参数,那可能是idFTP版本较早。
我用的是idFTP V9.0是有AResume参数的。
procedure TFTPModel.Upload;function RemoveExt(const AFileName: String): String;
{ Helper function to removes the extension from a file name. }
begin
if Pos('.', AFileName) <> 0 then
Result := Copy(AFileName, 1, Pos('.', AFileName)-1)
else
Result := AFileName;
end;var
FileName : string;
sZipFileName:string;
Item : TListItem;
QueueItem : TListItem;
begin
//没有登录文件服务器,不进行上传处理。
if not FFTPClient.Connected Then
begin
Application.MessageBox('没有登录文件传输服务器,不能上传文件',SysHintMsgTitle);
Exit;
end;
//没有选中目录
if FLVLocalFile.Selected = nil then Exit; Item := FLVLocalFile.Selected;
FLVQueue.Clear;
while Item <> nil do
begin
//这里加了约束,是文件夹的话,不加到上传队列,
//也就是说不支持文件夹的上传。
if Item.SubItems[0]<>'文件夹' then
begin
QueueItem := FLVQueue.Items.Add;
QueueItem.Caption := Item.Caption;
QueueItem.SubItems.Add(FLocaLPath);
QueueItem.SubItems.Add(Item.SubItems[1]);
QueueItem.SubItems.Add('->');
QueueItem.SubItems.Add('');
QueueItem.SubItems.Add(FRemotePath);
end;
Item:=FLVLocalFile.GetNextItem(Item,sdAll, [isSelected]);
end;
FLVQueue.Refresh;
{
LViewLocalFile.Enabled:=false;
LViewRemoteFile.Enabled:=False;
RemoteUpDir.Enabled:=false;
}
//上传文件。表示正在上传
FLoadOption:=loUpLoad;
try
while FLVQueue.Items.Count > 0 do
begin
FileName:=FLVQueue.Items[0].Caption;
FLVQueue.Items[0].SubItems[3]:='正在上传';
FLVQueue.Refresh;
//本来上传语句是下面这句,由于,怕出现 中断上传 的问题,也就是服务端有该目录,
//所以注释这句。采用下面这句,追加上传。
// 2005-3-11 中午,覆盖模式。
//FFTPClient.Put(FLocalPath+'\'+FileName, FileName);
//追加模式,再文件后面追加内容。
{//断点传输解决方案。
问: 请问idftp能否做到断点续传,下载倒是蛮好实现的,但是不知道上传要怎么做到断点续传???
且如果文件名未改变,但文件改变了,下载(断点续传)时是否会自动判断???
答: 上传断点续传原理是这样的:
假设有个 file.zip 传了50%断掉后
先 resumepoint:=idftp1.size('file.zip');
再 打开 本地 file.zip 到fileStream,seek 到 resumepoint;
idftp1.Quote('REST '+floattostr(resumepoint));
idftp1.put(fileStream,Orderputfilename,true);
关键一点是要修改indy 的源代码
indy是用sendcmd 'APPE' 方式续上传的,要改为sendcmd 'STOR'
---
注:本方法在serv-u 5.0 ,indy 9.0.4上测试通过
} //压缩文件
{sZipFileName:=RemoveExt(FileName)+'.Zip';
FVCLZip.FilesList.Clear;
FVCLZip.FilesList.Add(FLocalPath+'\'+FileName);
FVCLZip.ZipName:=FLocalPath+'\'+sZipFileName;
FVCLZip.Zip;} //以前的代码注释于 2005年4月14日
(* 用Size方法就可以!返回 550就文件不存在 213就存在 *)
//远程存在,则删除
if FFTPClient.Size(FRemotePath+sZipFileName)>-1 then
begin
FFTPClient.Delete(FRemotePath+sZipFileName);
end; //上传文件函数
FFTPClient.Put(FLocalPath+'\'+sZipFileName, sZipFileName,True);
//删除本地临时文件
DeleteFile(PChar(FLocalPath+'\'+sZipFileName)); //更新远程路径。
//*********
RemoteChangeDir;
FLVQueue.items[0].Delete;
FLVQueue.Refresh;;
end;
FLoadOption:=loNone;
except
FLVQueue.Items[0].SubItems[3]:='错误';
FLoadOption:=loNone;
end;
end;
上传还是不可以续传!