unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Dialogs, StdCtrls,
IdFTP, IdFTPCommon, IdFTPList;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
Connection: TIdFTP;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
const
strHost = 'ftp.freepascal.org';
strUser = 'anonymous';
strPassword = 'anonymous@domain.com';
var
i: Integer;
begin
Connection := TIdFTP.Create(nil);
// Connect
with Connection do
begin
Host := strHost;
Username := strUser;
Password := strPassword;
try
Connect;
except
on E: Exception do
begin
ShowMessage('Unable to connect to the FTP server.');
Free;
Exit;
end;
end;
end;
// List files
with Connection do
begin
try
List('', False);
except
on E: Exception do
begin
ShowMessage('FTP List command failed.');
Free;
Exit;
end;
end;
Memo1.Clear;
for i := 0 to DirectoryListing.Count-1 do
Memo1.Append(DirectoryListing.Items[i].FileName);
end;
Connection.Free;
end;
end.