Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get Filenames in a Remote Directory
Gets the names of files in a remote FTP directory.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Ftp2;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ftp: TFtp2;
n: Integer;
i: Integer;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
ftp := TFtp2.Create;
ftp.Hostname := 'ftp.example.com';
ftp.Username := 'myLogin';
ftp.Password := 'myPassword';
// Use explicit TLS
ftp.AuthTls := True;
ftp.Port := 21;
// Connect and login to the FTP server.
success := ftp.Connect();
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Iterate over .txt files.
ftp.ListPattern := '*.txt';
n := ftp.GetDirCount();
WriteLn('n = ' + n);
i := 0;
while i < n do
begin
WriteLn(i + ': ' + ftp.GetFilename(i));
i := i + 1;
end;
ftp.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.