Lazarus

Programming => General => Topic started by: roel53 on October 09, 2019, 09:45:47 pm

Title: FTP File list
Post by: roel53 on October 09, 2019, 09:45:47 pm
Hi !
I'm a newbie here... and also quite new in Lazarus but enjoying it.
I want to create a list of my FTP files in a TMemo and by clicking one it would be downloaded.
Can someone help me in the right direction ?
Thanks.
Title: Re: FTP File list
Post by: howardpc on October 09, 2019, 10:48:41 pm
You probably want to list your data in a listbox (not a memo) to make itemised selection straightforward.
Use the listbox's OnClick (or OnSelectionChange) event to identify the correct item to be downloaded.
Title: Re: FTP File list
Post by: wp on October 10, 2019, 10:16:39 am
Maybe the question was how to download a file list from an ftp server?
Title: Re: FTP File list
Post by: dsiders on October 10, 2019, 03:54:23 pm
Maybe the question was how to download a file list from an ftp server?

If it was, the answer should be to use something with a proper FTP client. Indy has a comprehensive one.
Title: Re: FTP File list
Post by: roel53 on October 10, 2019, 05:39:04 pm
The main problem is how to get the list of files (in a given directory) into a 'ListBox' (as suggested by howardpc)
I got so far now that I can download a specific file from my FTP server. (see code)(uses FTPSend)
Now I need a list with the contents of a specific folder on my FTP server.
Any help is appreciated.

Code: Pascal  [Select][+][-]
  1. uses FTPSend;
  2.  
  3. var
  4.   domain : String;
  5.   remoteFile : String;
  6.   localFile : String;
  7.   userName : String;
  8.   pasWord : String;
  9.  
  10. { TForm1 }
  11.  
  12. procedure TForm1.Button1Click(Sender: TObject);
  13. begin
  14.    domain := Edit1.text;
  15.    remoteFile :='/TEST_Roel/20491_20191005_235121.txt';
  16.    localFile := 'C:\Users\Roel\Downloads\Test_FTP_File_download\test1.txt';
  17.    userName := Edit2.text;
  18.    pasWord := Edit3.text;
  19.  
  20.   if ftpGetFile(domain,'21', remoteFile, localFile, userName, pasWord) then
  21.     Edit4.text :='SUCCES' else Edit4.text :='FAIL';
  22.  
  23. end;  
Title: Re: FTP File list
Post by: lucamar on October 10, 2019, 06:42:03 pm
In Synapse, a listing of remote files can be retrieved with TFTPSend.List(); after calling that method the list is available in property: TFTPSend.FtpList. It's a TFTPList object so you'll have to do some massaging to show the filenames in a listbox.

Indy has similar methods/properties as do most any "framework" FTP client classes, given that LIST is a basic, standard FTP command.

HTH
Title: Re: FTP File list
Post by: wp on October 11, 2019, 12:35:36 pm
Since I've never done anything with FTP yet I wrote a demo for myself which uses synapse to create a file list of a directory of the freepascal.org ftp server. Maybe it is helpful.
Title: Re: FTP File list
Post by: roel53 on October 11, 2019, 04:23:32 pm
Since I've never done anything with FTP yet I wrote a demo for myself which uses synapse to create a file list of a directory of the freepascal.org ftp server. Maybe it is helpful.

This is great...I can definitely work with this demo to achieve my goal.
I'll go through your code and study...learning every day !
Thank you so much wp, you made my day !  :) :) :)
TinyPortal © 2005-2018