Lass IdFTP die Arbeit machen
Hier mal ein Ausschnitt aus meiner FTPBrowser-
Unit:
Delphi-Quellcode:
procedure TFtpBrowser.CreateDirectoryListing;
var
i: Integer;
begin
Working := True;
if FFtp.Connected then
begin
FFtp.SendCmd('TYPE A');
FFtp.List (nil, '-a', True);
for i := 0 to Pred (FFtp.ListResult.Count) do
CreateItemFromFileInfo (GetFileInfo(i));
end;
Working := False;
end;
procedure TFtpBrowser.CreateItemFromFileInfo(const FileInfo: TFileInfo);
var
ListItem: TListItem;
begin
if FileInfo.Filename <> '.' then
begin
ListItem := FFiles.Items.Add;
if FileInfo.FileType = 'Ordner' then
if Fileinfo.Filename <> '..' then
ListItem.ImageIndex := 0
else
ListItem.ImageIndex := 1
else
ListItem.ImageIndex := 2;
ListItem.Caption := FileInfo.Filename;
if FileInfo.Size > 1000000 then
ListItem.SubItems.Add(IntToStr (FileInfo.Size DIV 1000000) + ' MB')
else if FileInfo.Size > 1000 then
ListItem.SubItems.Add(IntToStr (FileInfo.Size DIV 1000) + ' KB')
else if FileInfo.Size > 0 then
ListItem.SubItems.Add(IntToStr (FileInfo.Size) + ' Byte')
else
ListItem.SubItems.Add('n/a');
ListItem.SubItems.Add(FileInfo.FileType);
ListItem.SubItems.Add(FileInfo.Date);
end;
end;