我用Indy的TIdFTPServer编写了FTP服务端程序,并用IE的Ftp可以列出服务器的目录,用D6的FTPDemo和ICS的FTP示例均能列出服务器的目录,但用Indy的FTP的Demos中的FTP客户端示例却不能列出服务器的目录。为此,我看了TidFTP和TIdFTPServer、TIdFTPList的源代码,也没发现问题。现把相应的过程附后,请教各位高手。谢谢!!Client:procedure TFormMain.ViewList;
var
DirList: TStringList;
i: Integer;
ListItem: TListItem;
Attribute: TIdDirItemType;
begin
//向ListViewRemote控件逐个添加FTP当前工作目录下的文件目录
DirList := TStringList.Create;
try
try
IdFTP1.List(DirList);
except;
end;
finally
DirList.Free;
end;
memoinfo.Lines.add(inttostr(IdFTP1.DirectoryListing.Count));
ListViewRemote.Clear;
for i := 0 to IdFTP1.DirectoryListing.Count - 1 do
begin
ListItem := ListViewRemote.Items.Add();
ListItem.Caption := IdFTP1.DirectoryListing[i].FileName;
ListItem.SubItems.Add(IntToStr(IdFTP1.DirectoryListing[i].Size));
ListItem.SubItems.Add(DateToStr(IdFTP1.DirectoryListing[i].ModifiedDate));
Attribute := IdFTP1.DirectoryListing[i].ItemType;
if Attribute = ditDirectory then
begin
//本项是目录
ListItem.SubItems.Add('目录');
ListItem.ImageIndex := 0
end
else if Attribute = ditFile then
begin
//本项是文件
ListItem.SubItems.Add('文件');
ListItem.ImageIndex := 1
end
else if Attribute = ditSymbolicLink then
begin
ListItem.SubItems.Add('符号链接');
ListItem.ImageIndex := 2
end;
end;
end;Servser:procedure TMainForm.IdFTPServer1ListDirectory(ASender: TIdFTPServerThread;
const APath: String; ADirectoryListing: TIdFTPListItems);
var
item: TIdFTPListItem;
flag:integer;
SRec:TSearchRec;
begin
ADirectoryListing.ListFormat:=flfdos;
Flag:=FindFirst(Pchar('D:\common\*.*'),faAnyFile,Srec);
if Flag=0 then
begin
item := ADirectoryListing.Add;
item.FileName := SRec.Name;
if Srec.attr=16 then
item.ItemType := ditDirectory
else item.itemtype:=ditfile;
item.Size:=Srec.Size;
item.ModifiedDate:=FileDateToDateTime(SRec.Time);
end;
while (FindNext(SRec) = 0) do
begin
item := ADirectoryListing.Add;
item.FileName := SRec.Name;
if Srec.attr=16 then
item.ItemType := ditDirectory
else item.itemtype:=ditfile;
item.Size:=Srec.Size;
item.ModifiedDate:=FileDateToDateTime(SRec.Time);
end;
findclose(Srec);
end;
var
DirList: TStringList;
i: Integer;
ListItem: TListItem;
Attribute: TIdDirItemType;
begin
//向ListViewRemote控件逐个添加FTP当前工作目录下的文件目录
DirList := TStringList.Create;
try
try
IdFTP1.List(DirList);
except;
end;
finally
DirList.Free;
end;
memoinfo.Lines.add(inttostr(IdFTP1.DirectoryListing.Count));
ListViewRemote.Clear;
for i := 0 to IdFTP1.DirectoryListing.Count - 1 do
begin
ListItem := ListViewRemote.Items.Add();
ListItem.Caption := IdFTP1.DirectoryListing[i].FileName;
ListItem.SubItems.Add(IntToStr(IdFTP1.DirectoryListing[i].Size));
ListItem.SubItems.Add(DateToStr(IdFTP1.DirectoryListing[i].ModifiedDate));
Attribute := IdFTP1.DirectoryListing[i].ItemType;
if Attribute = ditDirectory then
begin
//本项是目录
ListItem.SubItems.Add('目录');
ListItem.ImageIndex := 0
end
else if Attribute = ditFile then
begin
//本项是文件
ListItem.SubItems.Add('文件');
ListItem.ImageIndex := 1
end
else if Attribute = ditSymbolicLink then
begin
ListItem.SubItems.Add('符号链接');
ListItem.ImageIndex := 2
end;
end;
end;Servser:procedure TMainForm.IdFTPServer1ListDirectory(ASender: TIdFTPServerThread;
const APath: String; ADirectoryListing: TIdFTPListItems);
var
item: TIdFTPListItem;
flag:integer;
SRec:TSearchRec;
begin
ADirectoryListing.ListFormat:=flfdos;
Flag:=FindFirst(Pchar('D:\common\*.*'),faAnyFile,Srec);
if Flag=0 then
begin
item := ADirectoryListing.Add;
item.FileName := SRec.Name;
if Srec.attr=16 then
item.ItemType := ditDirectory
else item.itemtype:=ditfile;
item.Size:=Srec.Size;
item.ModifiedDate:=FileDateToDateTime(SRec.Time);
end;
while (FindNext(SRec) = 0) do
begin
item := ADirectoryListing.Add;
item.FileName := SRec.Name;
if Srec.attr=16 then
item.ItemType := ditDirectory
else item.itemtype:=ditfile;
item.Size:=Srec.Size;
item.ModifiedDate:=FileDateToDateTime(SRec.Time);
end;
findclose(Srec);
end;
ADirectoryListing.BeginUpdate;
不然 ADirectoryListing.Add;不会生效