Atozed Forums
FTP get list of folders - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Indy (https://www.atozed.com/forums/forum-8.html)
+--- Forum: Indy General Discussion (https://www.atozed.com/forums/forum-9.html)
+--- Thread: FTP get list of folders (/thread-2614.html)



FTP get list of folders - enriquepsmac - 01-08-2022

Hello i working on lazarus ineed get a list f folders on ftpserver but allways show me empty list 

here my code  hope some body help me what i made wrong...

procedure TFomMain.FormShow(Sender: TObject);
var i,ld:integer;
  Tr:tstrings;
  fiConfusedtring;
  Tt:tidftplistitems;
  T:tidftplistitem;
begin
  FPXMLBFtp.LoadFromFile('FTPSetting.xml');
  TR:= Tstringlist.create;
  idFTP1.Host:= FPXMLBFTP.GetAttrValueByName('Server.ip', 'value');
  idFTP1.Passive:=true;
  idFTP1.Username:=FPXMLBFTP.GetAttrValueByName('Server.user', 'value');
  idFTP1.Password:=FPXMLBFTP.GetAttrValueByName('Server.password', 'value');
  idFTP1.Port:=strtoint(FPXMLBFTP.GetAttrValueByName('Server.port', 'value'));
  Statusbar1.Panels[0].Text:='No Conncted , wait';
  idFTP1.Connect;
  if(idFTP1.Connected = true) then begin
    Statusbar1.Panels[0].Text:='Conncted to '+ idFTP1.Host;
    idFTP1.ChangeDir('..');
    idFTP1.List('*',true);
    Memo1.Lines.Add(idFTP1.RetrieveCurrentDir);
    Memo1.Lines.Add( InttoSTr(idFTP1.ListResult.Count));
    for i:=0 to Idftp1.directorylisting.Count-1 do begin
      if((IdFTP1.DirectoryListing[I].ItemType = ditDirectory) and (IdFTP1.DirectoryListing[I].FileName <> '.') and (IdFTP1.DirectoryListing[I].FileName <> '..')) then begin
        Memo1.Lines.Add(IdFTP1.DirectoryListing[I].FileName);
      end else  if( IdFTP1.DirectoryListing[I].ItemType = ditFile) then begin
        Memo1.Lines.Add(IdFTP1.DirectoryListing[I].FileName);
      end;
    end;

//  Listbox1.Items.Assign(Idftp1.directorylisting.Items);
    Memo1.Lines.Add(idftp1.retrievecurrentdir);
//  idFTP1.ChangeDir('Parts_Vendors');
//  idFTP1.List(TR);
//  Listbox1.Items.Assign(tr);
//  Memo1.Lines.Assign (TR);
//  if( FPXMLBFtp.GetAttrValueByName('Server.actiontoFtp', 'value') = 'Upload') then begin
//      UploadFile(Sender);
//  end else begin
//      DownloadFile(Sender);
//  end;

end;


RE: FTP get list of folders - rlebeau - 01-10-2022

(01-08-2022, 07:39 PM)enriquepsmac Wrote: Hello i working on lazarus ineed get a list f folders on ftpserver but allways show me empty list 

The code looks fine to me. Did you verify the server is actually sending a non-empty list to begin with? What does TIdFTP.ListResult actually contain? Do you have any IdFTPListParse... units in your uses clause? What is the value of TIdFTP.DirFormat after TIdFTP.DirectoryListing has parsed TIdFTP.ListResult?