Recent

Author Topic: FTP File list  (Read 400 times)

roel53

  • Newbie
  • Posts: 3
FTP File list
« 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.

howardpc

  • Hero Member
  • *****
  • Posts: 3148
Re: FTP File list
« Reply #1 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.

wp

  • Hero Member
  • *****
  • Posts: 6228
Re: FTP File list
« Reply #2 on: October 10, 2019, 10:16:39 am »
Maybe the question was how to download a file list from an ftp server?
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

dsiders

  • Full Member
  • ***
  • Posts: 220
Re: FTP File list
« Reply #3 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.
Lazarus 2.0.4 / FPC 3.0.4 / Windows 8.1 64-bit

roel53

  • Newbie
  • Posts: 3
Re: FTP File list
« Reply #4 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;  

lucamar

  • Hero Member
  • *****
  • Posts: 2016
Re: FTP File list
« Reply #5 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
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

wp

  • Hero Member
  • *****
  • Posts: 6228
Re: FTP File list
« Reply #6 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.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

roel53

  • Newbie
  • Posts: 3
Re: FTP File list
« Reply #7 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 !  :) :) :)