Recent

Author Topic: [solved] Indy FTP List Fails  (Read 533 times)

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • My goal: build my own game engine using Lazarus
[solved] Indy FTP List Fails
« on: October 22, 2020, 04:23:34 am »
Indy FTP List works on Ubuntu Mate but it fails if I cross compile the same code and test it on WinXP. That should not be the problem of the WinXP because I can access the FTP using Firefox on the WinXP. Does Internet Direct not support WinXP?

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Dialogs, StdCtrls,
  9.   IdFTP, IdFTPCommon, IdFTPList;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Memo1: TMemo;
  18.     procedure Button1Click(Sender: TObject);
  19.   private
  20.     Connection: TIdFTP;
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.Button1Click(Sender: TObject);
  33. const
  34.   strHost     = 'ftp.freepascal.org';
  35.   strUser     = 'anonymous';
  36.   strPassword = 'anonymous@domain.com';
  37. var
  38.   i: Integer;
  39. begin
  40.   Connection := TIdFTP.Create(nil);
  41.  
  42.   // Connect
  43.   with Connection do
  44.   begin
  45.     Host     := strHost;
  46.     Username := strUser;
  47.     Password := strPassword;
  48.     try
  49.       Connect;
  50.     except
  51.       on E: Exception do
  52.         begin
  53.           ShowMessage('Unable to connect to the FTP server.');
  54.           Free;
  55.           Exit;
  56.         end;
  57.     end;
  58.   end;
  59.  
  60.   // List files
  61.   with Connection do
  62.   begin
  63.     try
  64.       List('', False);
  65.     except
  66.       on E: Exception do
  67.         begin
  68.           ShowMessage('FTP List command failed.');
  69.           Free;
  70.           Exit;
  71.         end;
  72.     end;
  73.     Memo1.Clear;
  74.     for i := 0 to DirectoryListing.Count-1 do
  75.       Memo1.Append(DirectoryListing.Items[i].FileName);
  76.   end;
  77.  
  78.   Connection.Free;
  79. end;
  80.  
  81. end.

Note:
The code needs Indy10, you can install it using Online Package Manager.
« Last Edit: October 22, 2020, 07:50:53 pm by Handoko »

GAN

  • Sr. Member
  • ****
  • Posts: 305
Re: Indy FTP List Fails
« Reply #1 on: October 22, 2020, 05:00:32 am »
May be the firewall.
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7.2.6 - Sqlite 3.32.3

https://gitlab.com/users/GAN__/projects

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • My goal: build my own game engine using Lazarus
Re: Indy FTP List Fails
« Reply #2 on: October 22, 2020, 05:18:04 am »
I already disabled the firewall. First time running the program, WinXP told me the firewall blocked it, so I disabled the entire firewall.

My test shows, it was able to connect to the FTP without any issue but the exception happened when it tried to do listing.

GAN

  • Sr. Member
  • ****
  • Posts: 305
Re: Indy FTP List Fails
« Reply #3 on: October 22, 2020, 07:25:39 am »
I'd try specifying port 21.
I use synapse but it should be similar.

Code: Pascal  [Select][+][-]
  1. ftp.Username := 'user@domain.com';
  2.     ftp.Password := 'thepass';
  3.     ftp.TargetHost := 'ftp.domain.com';
  4.     ftp.TargetPort := '21';
  5.     ftp.Timeout:=4000;
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7.2.6 - Sqlite 3.32.3

https://gitlab.com/users/GAN__/projects

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • My goal: build my own game engine using Lazarus
Re: Indy FTP List Fails
« Reply #4 on: October 22, 2020, 08:14:12 am »
I manually set the port to 21 before connecting but the result was same:

Code: Pascal  [Select][+][-]
  1.     Port     := 21;
  2.     Host     := strHost;
  3.     Username := strUser;
  4.     Password := strPassword;

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 862
Re: Indy FTP List Fails
« Reply #5 on: October 22, 2020, 10:58:17 am »
hello,
have you try :
Code: Pascal  [Select][+][-]
  1.  
  2.       List('*', False);
  3.  
or :
Code: Pascal  [Select][+][-]
  1.       List('*.*', False);
  2.  
You can try to use another FTP component. For example TLFTPClientComponent from Lnet package (in OPM).
screenshot of the  lnet/examples/visual/ftp/ftptest  in attachment
Friendly, J.P


Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 837
    • Lebeau Software
Re: Indy FTP List Fails
« Reply #6 on: October 22, 2020, 07:01:45 pm »
Indy FTP List works on Ubuntu Mate but it fails if I cross compile the same code and test it on WinXP. That should not be the problem of the WinXP because I can access the FTP using Firefox on the WinXP.

What is the actual error that TIdFTP.List() is raising?  You are catching the exception, but you are discarding it and not displaying any of its details, like its ClassType or its Message.  Same with TIdFTP.Connect().

Have you tried sniffing the network traffic to compare what is different between Firefox's FTP commands vs TIdFTP's commands?

Does Internet Direct not support WinXP?

Yes, it does.  Windows it the primary OS that Indy is developed on, so everything should be working fine on Windows. But this does not sound like an OS-based issue.

Note that data transfers in the FTP protocol use a secondary TCP connection, and default to Active mode (TIdFTP.Passive=False) where the FTP server creates an outgoing connection to the FTP client.  That is not very friendly to firewalls/NATs, and requires port forwarding be configured on NATs.  Try using Passive mode instead (TIdFTP.Passive=True) where the FTP client creates an outbound connection to the FTP server instead.  That usually works better.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • My goal: build my own game engine using Lazarus
Re: Indy FTP List Fails
« Reply #7 on: October 22, 2020, 07:50:11 pm »
Yes, you're right. By setting Passive := True, it works correctly now. Thank you.

And thank you everyone who trying to help me. I previously used lNet because I like its simplicity. I already wrote many functions using it but until I found lNet FTP download usually does not finish at 100% if the file size is above 1 MB, even without any error. Maybe I did it wrong so I tested and examined the examples bundled with the download. Sadly, not always but sometimes it crashes running on my machine.

 

TinyPortal © 2005-2018