转帖一个 nmftp控件的例子,其实就是递归使用
procedure DownLoadDirectory(Dir:string;FtpSvr: TNMFTP): integer;
var
AttList : TStrings;
NameList : TStrings;
count : integer;
i : integer;
Att : string;
begin
AttList := TStringList.Create;
NameList:= TStringList.Create;
FtpSvr.List;
AttList.Assign( FtpSvr.FTPDirectoryList.Attribute );
NameList.Assign(FtpSvr.FTPDirectoryList.name );
count := AttList.Count;
Chdir(dir);
if count = 0 then exit;
for i:=0 to count-1 do
begin
Att := AttList.Strings;
if( Att[1] = '-' ) then
begin
try
FtpSvr.Download( nameList.Stringsi],dir+ '/'+NameList.Strings );
except end;
end;
if( Att[1] = 'd' ) then
begin
mkdir(NameList.strings);
try
FtpSvr.ChangeDir(NameList.strings);
except end;
DownLoadDirectory( dir+'/'+NameList.Strings, FtpSvr );
chdir(dir);
try
FtpSvr.ChangeDir('..');
except end;
end;
end;
end;