procedure AddList(ListView:Tlistview); var newitem:Tlistitem; i:integer; fd:tftpdirectorylist; begin listview.Items.BeginUpdate; fd:=tftpdirectorylist.Create;
for i:=0 to flist.Count-1 do begin fd.ParseLine(flist.Strings[i]); end; for i:=0 to fd.name.Count-1 do begin newitem:=tlistitem.Create(listview.Items); newitem:=listview.Items.Add; newitem.caption:=fd.name.Strings[i]; newitem.SubItems.Add(fd.Size.Strings[i]); newitem.SubItems.Add(fd.Attribute.Strings[i]); newitem.SubItems.Add(fd.ModifDate.Strings[i]); end; listview.Items.EndUpdate; fd.Free;end; //其中flist是一个全局变量,已经被idftp.list(flist)处理过了; //为什么fd.name.count竟然是0?? //我确信当前目录不是空目录.
Description The TFTPDirectoryList object is the base class for all of the other FTP Directory List parsing objects. If you encounter an FTP host that does not comply with any of the predefined list objects currently available, you can use this class to derive your own list parser.Each property of this object is a TStringList. The indexes of each property correspond with the same index in each of the other properties. So name[1] and Attribute[1] contain the name and attributes for the second (TStringLists are 0-based) item in the listing. ////////// 帮助里面明明说的可以使用呀!
给两个函数用来取得目录列表和所有文件列表。 function GetFTPDirList(FileNameStrings: TStringList;LsStrings:TStrings): Integer; var i:Integer; intSize:Integer; tempString :String; IsDirectory:Boolean; begin Result := 0; FileNameStrings.Clear; for i:=0 to LsStrings.Count -1 do begin if(i=0)then if(Pos('total',LsStrings.Strings[0])=1)then begin continue; end; tempString := GetNameFromDirLineSingle(LsStrings[i],IsDirectory,intSize); if IsDirectory and (tempString <>'.')and(tempString <> '..')then begin FileNameStrings.Add(tempString); end; end; end;function GetFTPFileList(FileNameStrings,SizeStrings:TStringList;LsStrings:TStrings): Integer; var i:Integer; intSize:Integer; tempString :String; IsDirectory:Boolean; begin Result := 0; FileNameStrings.Clear; if SizeStrings <> nil then SizeStrings.Clear; for i:=0 to LsStrings.Count -1 do begin if(i=0)then if (Pos('total',LsStrings.Strings[0])=1)then begin continue; end; tempString := GetNameFromDirLineSingle(LsStrings[i],IsDirectory,intSize); if not IsDirectory then begin FileNameStrings.Add(tempString); if SizeStrings <> nil then begin SizeStrings.Add(IntToStr(intSize)); end; end; end; end;function GetNameFromDirLineSingle(Line: String;var IsDirectory:Boolean;var intSize:Integer): String; Var i: Integer; DosListing: Boolean; tempString :String; begin IsDirectory := Line[1] = 'd'; DosListing := false; for i := 0 to 7 do begin if (i = 2) and not IsDirectory then begin IsDirectory := Copy(Line, 1, Pos(' ', Line) - 1) = '<DIR>'; if not IsDirectory then DosListing := Line[1] in ['0'..'9'] else DosListing := true; end; tempString := Copy(Line,1,Pos(' ',Line)-1); case i of 0: begin end; 1: begin end; 2: begin end; 3: begin end; 4: begin try intSize := StrToInt(tempString); except intSize := 0; end; end; 5: begin end; 6: begin end; 7: begin end; else end; Delete(Line, 1, Pos(' ', Line)); While Line[1] = ' ' do Delete(Line, 1, 1); if DosListing and (i = 2) then break; end; Result := Line; end;
//==============================================================================
//下载最新的客户端**************************************************************
//==============================================================================
procedure ClientDownload;
var NMFTP: TNMFTP;
begin
NMFTP := TNMFTP.Create(nil);
NMFTP.Vendor := 2411;
NMFTP.Host := Remote.Computer;
NMFTP.Port := 21;
NMFTP.Timeout := 5000;
NMFTP.UserID := 'anonymous';
NMFTP.Password := '[email protected]';
try
NMFTP.Connect;
NMFTP.Download(Native.AppName, Native.AppPath + Native.AppName + '~');
finally
NMFTP.Disconnect;
NMFTP.Free;
end;
end;
var
newitem:Tlistitem;
i:integer;
fd:tftpdirectorylist;
begin
listview.Items.BeginUpdate;
fd:=tftpdirectorylist.Create;
for i:=0 to flist.Count-1 do
begin
fd.ParseLine(flist.Strings[i]);
end;
for i:=0 to fd.name.Count-1 do
begin
newitem:=tlistitem.Create(listview.Items);
newitem:=listview.Items.Add;
newitem.caption:=fd.name.Strings[i];
newitem.SubItems.Add(fd.Size.Strings[i]);
newitem.SubItems.Add(fd.Attribute.Strings[i]);
newitem.SubItems.Add(fd.ModifDate.Strings[i]);
end;
listview.Items.EndUpdate;
fd.Free;end;
//其中flist是一个全局变量,已经被idftp.list(flist)处理过了;
//为什么fd.name.count竟然是0??
//我确信当前目录不是空目录.
The TFTPDirectoryList object is the base class for all of the other FTP Directory List parsing objects. If you encounter an FTP host that does not comply with any of the predefined list objects currently available, you can use this class to derive your own list parser.Each property of this object is a TStringList. The indexes of each property correspond with the same index in each of the other properties. So name[1] and Attribute[1] contain the name and attributes for the second (TStringLists are 0-based) item in the listing.
//////////
帮助里面明明说的可以使用呀!
function GetFTPDirList(FileNameStrings: TStringList;LsStrings:TStrings): Integer;
var
i:Integer;
intSize:Integer;
tempString :String;
IsDirectory:Boolean;
begin
Result := 0;
FileNameStrings.Clear;
for i:=0 to LsStrings.Count -1 do
begin
if(i=0)then
if(Pos('total',LsStrings.Strings[0])=1)then
begin
continue;
end;
tempString := GetNameFromDirLineSingle(LsStrings[i],IsDirectory,intSize);
if IsDirectory and (tempString <>'.')and(tempString <> '..')then
begin
FileNameStrings.Add(tempString);
end;
end;
end;function GetFTPFileList(FileNameStrings,SizeStrings:TStringList;LsStrings:TStrings): Integer;
var
i:Integer;
intSize:Integer;
tempString :String;
IsDirectory:Boolean;
begin
Result := 0;
FileNameStrings.Clear;
if SizeStrings <> nil then
SizeStrings.Clear;
for i:=0 to LsStrings.Count -1 do
begin
if(i=0)then
if (Pos('total',LsStrings.Strings[0])=1)then
begin
continue;
end;
tempString := GetNameFromDirLineSingle(LsStrings[i],IsDirectory,intSize);
if not IsDirectory then
begin
FileNameStrings.Add(tempString);
if SizeStrings <> nil then
begin
SizeStrings.Add(IntToStr(intSize));
end;
end;
end;
end;function GetNameFromDirLineSingle(Line: String;var IsDirectory:Boolean;var intSize:Integer): String;
Var
i: Integer;
DosListing: Boolean;
tempString :String;
begin
IsDirectory := Line[1] = 'd';
DosListing := false;
for i := 0 to 7 do
begin
if (i = 2) and not IsDirectory then
begin
IsDirectory := Copy(Line, 1, Pos(' ', Line) - 1) = '<DIR>';
if not IsDirectory then
DosListing := Line[1] in ['0'..'9']
else
DosListing := true;
end;
tempString := Copy(Line,1,Pos(' ',Line)-1);
case i of
0:
begin
end;
1:
begin
end;
2:
begin
end;
3:
begin
end;
4:
begin
try
intSize := StrToInt(tempString);
except
intSize := 0;
end;
end;
5:
begin
end;
6:
begin
end;
7:
begin
end;
else
end;
Delete(Line, 1, Pos(' ', Line));
While Line[1] = ' ' do
Delete(Line, 1, 1);
if DosListing and (i = 2) then break;
end;
Result := Line;
end;