TIdFTPServer响应TIdFTP.List的问题

gzbchina 2004-04-22 06:51:55
我用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;
...全文
584 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
mydelphiworld 2004-07-24
  • 打赏
  • 举报
回复
up
Clamfly 2004-07-18
  • 打赏
  • 举报
回复
CommandOPTS过程在Indy的源代码中,修改后你需要重新编译Indy组件。
Clamfly 2004-07-18
  • 打赏
  • 举报
回复
如果是中文目录乱码问题,解决如下:

IE在LIST命令之前会发送一个opts utf8 on 命令启用utf8格式的文件名传输,

但TIdFTPServer不支持这个功能,会产生一个202回复。

麻烦就在这里,IE忽略了这个202回复并继续以utf8模式处理服务器发送的ANSI数据,导致列表混乱。

解决办法是找到CommandOPTS过程,把回复代码改为502或504。
dychen 2004-05-08
  • 打赏
  • 举报
回复
最后加上
ADirectoryListing.BeginUpdate;
不然 ADirectoryListing.Add;不会生效

830

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧