如何用idftp遍历整个目录----下载、删除_delphi教程

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,IdFTPList,
  IdTCPClient, IdFTP ;

type
  TForm1 = class(TForm)
    Btt_DownLoadDir: TButton;
    IdFTP1: TIdFTP;
    Btt_DeleteDir: TButton;
    Label1: TLabel;
    lb_num: TLabel; //处理文件个数提示。
    procedure Btt_DownLoadDirClick(Sender: TObject);
    procedure Btt_DeleteDirClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ 下载整个目录,并遍历所有子目录

首先 ChangeDir(Root) 到根目录

然后创建本地目录 + RemoteDir

然后用 list 得到所有目录名

循环判断,进入 RemoteDir 目录内部

如果是目录继续第归。否则 get 该文件到本地目录,当 get 完所有文件后返回上一级目录

用List再取得信息,继续循环

}

procedure FTP_DownloadDir(var idFTP : TIdFtp;RemoteDir,LocalDir : string);

label Files ;

var

i,DirCount : integer;

begin

if not DirectoryExists(LocalDir + RemoteDir) then

ForceDirectories(LocalDir + RemoteDir);

idFTP.ChangeDir(RemoteDir);

idFTP.List(nil);

DirCount := idFTP.DirectoryListing.Count ;

if DirCount = 0 then

begin

idFTP.ChangeDirUp;

idFTP.List(nil);

end;

for i := 0 to DirCount - 1 do

begin

if DirCount <> idFTP.DirectoryListing.Count then

begin

repeat

idFTP.ChangeDirUp;

idFTP.List(nil);

until DirCount = idFTP.DirectoryListing.Count ;

end;

if idFTP.DirectoryListing[i].ItemType = ditDirectory then

FTP_DownloadDir(idFTP,idFTP.DirectoryListing[i].FileName,LocalDir + RemoteDir + \)

else begin

idFTP.Get(idFTP.DirectoryListing[i].FileName,LocalDir + RemoteDir + \ +

idFTP.DirectoryListing[i].FileName,true);

Form1.lb_num.Caption := IntToStr(StrToInt(Form1.lb_num.Caption) + 1);

Form1.lb_num.Update;

if i = DirCount - 1 then

begin

idFTP.ChangeDirUp;

idFTP.List(nil);

end;

end;

end;

end;

{删除整个ftp目录,包括下面的文件,

RootDir = 要删除的根目录,一般情况下 RemoteDir 与 RootDir 相等}

procedure FTP_DeleteAllFiles(var idFTP : TIdFtp;RemoteDir,RootDir : string);

label Files;

var

i,DirCount : integer;

Temp : string;

begin

idFTP.ChangeDir(RemoteDir);

if Pos(RootDir,idFTP.RetrieveCurrentDir) = 0 then Exit;

Files :

idFTP.List(nil);

DirCount := idFTP.DirectoryListing.Count ;

while DirCount = 0 do

begin

Temp := idFTP.RetrieveCurrentDir;

idFTP.ChangeDirUp;

idFTP.RemoveDir(Temp);

idFTP.List(nil);

DirCount := idFTP.DirectoryListing.Count ;

for i := 0 to DirCount - 1 do

if idFTP.DirectoryListing[i].FileName = RootDir then Exit;

end;

for i := 0 to DirCount - 1 do

begin

if Pos(RootDir,idFTP.RetrieveCurrentDir) = 0 then Break ;

if idFTP.DirectoryListing[i].ItemType = ditDirectory then

begin

FTP_DeleteAllFiles(idFTP,idFTP.DirectoryListing[i].FileName,RootDir);

end else begin

idFTP.Delete(idFTP.DirectoryListing[i].FileName);

Form1.lb_num.Caption := IntToStr(StrToInt(Form1.lb_num.Caption) + 1);

Form1.lb_num.Update;

goto Files ;

end;

end;

end;

procedure TForm1.Btt_DownLoadDirClick(Sender: TObject);

begin

IdFTP1.Connect(true,-1);

if IdFTP1.Connected then

begin

IdFTP1.ChangeDir(bigimage);

FTP_DownloadDir(IdFTP1,1002.1002.1002,g:\ftpdir\);

end;

IdFTP1.Disconnect ;

end;

procedure TForm1.Btt_DeleteDirClick(Sender: TObject);

begin

IdFTP1.Connect(true,-1);

if IdFTP1.Connected then

begin

IdFTP1.ChangeDir(bigimage);

FTP_DeleteAllFiles(IdFTP1,1002.1002.1002,1002.1002.1002);

end;

IdFTP1.Disconnect ;

end;

end.

如何用idftp遍历整个目录----下载、删除_delphi教程相关推荐

  1. Delphi 用IdFtp控件实现ftp的全目录下载

    首先是在本机上建立一个FTP服务器,方法参考[百度经验-Windows7上开启ftp服务器功能]http://jingyan.baidu.com/article/f54ae2fc3521d51e92b ...

  2. c++ 遍历多级目录

    参考:https://blog.csdn.net/sazass/article/details/100163264 TraverseDirectory可以遍历多级目录 getFiles不能遍历多级目录 ...

  3. wget指定目录下载以及其它的使用方式

    wget指定目录下载以及其它的使用方式 转自 http://java-er.com/blog/wget-useage-x/ 有时候我们需要wget一个文件下载到指定的目录下,或者重命名成指定的名字 w ...

  4. 目录遍历漏洞:入侵检测php程序中的目录遍历漏洞,目录浏览(目录遍历)漏洞

    目录浏览(目录遍历)漏洞 来源:信管网 2019年08月26日 [所有评论] 目录浏览漏洞属于目录遍历漏洞的一种 目录浏览(目录遍历)漏洞 目录浏览漏洞是由于网站存在配置缺陷,导致网站目录可以被任意浏 ...

  5. c# 遍历文件夹深度_C#.NET中遍历指定目录下的文件(及所有子目录及子目录里更深层目录里的文件)...

    //遍历一个目录下所有的文件列表,代码实例 DirectoryInfo dir = new DirectoryInfo(folderName); var list = GetAll(dir); /// ...

  6. ACCESS数据库的压缩,备份,还原,下载,删除的实现

    以文本方式查看主题 -  企胜MIS开发论坛|ASP.NET|UML| CSS|Access|My SQL|网络营销|JAVA|J2EE|Ajax  (http://www.fleake.com/in ...

  7. 路径遍历(目录遍历)

    一.简介 路径遍历攻击也称为目录遍历,旨在,访问存储在web根文件夹之外的文件和目录.通过操纵带有"点-斜线(-)"序列及其变化的文件或使用绝对路径来引用文件的变量,来访问存储在文 ...

  8. bpcs uploader.php,linux 百度云bpcs_uploader上传 下载 删除等操作

    百度云bpcs_uploader ------------------------------------------------------------------ 上传文件到百度云命令: 在bpc ...

  9. 【工具类】遍历扫描目录下全部文件并列出

    package test20140715;import java.io.File;import org.junit.Test; /*** 遍历扫描目录下全部文件并列出* @author fushihu ...

  10. linux命令行下的ftp 多文件下载和目录下载

    目标ftp服务器是一个非标准端口的ftp 1.通过shell登录#ftp    //shell下输入ftp命令,进入到ftp提示符>open IP  PORT   //IP ,PORT对应为服务 ...

最新文章

  1. Cannot load onnxruntime.capi. Error: DLL load failed: 找不到指定的模块
  2. UA PHYS515 电磁理论I 麦克斯韦方程组基础5 电动力学的四类问题与对应的麦克斯韦方程
  3. 原型模式coding-克隆破坏单例
  4. 【树形DP】路径计数机(nowcoder 1103-B)
  5. java作为kafka生产者实验及Expiring超时问题解决
  6. [分布式训练] 单机多卡的正确打开方式:Horovod
  7. mysql数据库函数转义函数_MySql数据库-查询、插入数据时转义函数的使用
  8. powerDesigner需求建模
  9. Netty工作笔记0028---NIO 网络编程应用--群聊系统3--客户端编写1
  10. VMware中网络设置之host-only
  11. 计算机视觉应用培训心得体会,计算机视觉专题分享总结(附PPT)
  12. 计算机原理非门,反相器和非门有什么区别
  13. The current process just got forked. Disabling parallelism to avoid deadlocks.To disable this warnin
  14. 驾驶习惯也能识人?基于时空孪生神经网络的轨迹识别
  15. 图片自动适应表格的大小
  16. 水处理离子交换设备详解
  17. SOLIDWORKS螺纹显示处理方法
  18. 爬虫_app 4 app数据抓取入门
  19. 图书馆数据库资源访问方法
  20. 红帽系统服务器格式化,Redhat Linux默认的文件系统是什么格式?

热门文章

  1. ul阻燃标准有几个等级_UL阻燃等级说明
  2. 使用POI在线预览Word
  3. 计算机丢失boost,Win7系统安装后出现无法开启readyboost怎么办?
  4. Activiti7的用法和简述
  5. 斐讯T1刷机详细指南
  6. Lobooi个人作业:阅读与准备作业
  7. 快易需求文档编辑系统——测试心得
  8. QCC3040----SOC模块
  9. 【数字图像处理】实验三 图像分割(MATLAB实现)
  10. NanoHTTPD服务