Delphi DLL
Delphi DLL
Get FTP Directory Listing Information
See more FTP Examples
_LANGUAGE_ example showing how to get information about files and subdirectories in the current remote FTP directory.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Ftp2;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
ftp: HCkFtp2;
i: Integer;
n: Integer;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
ftp := CkFtp2_Create();
CkFtp2_putHostname(ftp,'ftp.example.com');
CkFtp2_putUsername(ftp,'login');
CkFtp2_putPassword(ftp,'password');
// Connect and login to the FTP server.
success := CkFtp2_Connect(ftp);
if (success <> True) then
begin
Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
Exit;
end;
// The ListPattern property is our directory listing filter.
// The default value is "*", which includes everything.
Memo1.Lines.Add(CkFtp2__listPattern(ftp));
// To get file and sub-directory information, simply
// loop from 0 to ftp.GetDirCount() - 1
n := CkFtp2_GetDirCount(ftp);
if (n < 0) then
begin
Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
Exit;
end;
if (n > 0) then
begin
for i := 0 to n - 1 do
begin
// Display the filename
Memo1.Lines.Add(CkFtp2__getFilename(ftp,i));
// Display the file size (in bytes)
Memo1.Lines.Add(IntToStr(CkFtp2_GetSize(ftp,i)));
// Is this a sub-directory?
if (CkFtp2_GetIsDirectory(ftp,i) = True) then
begin
Memo1.Lines.Add('.. this is a sub-directory');
end;
Memo1.Lines.Add('--');
end;
end;
Memo1.Lines.Add('-----------------------------------');
// Only files and directories
// matching the ListPattern are returned.
CkFtp2_putListPattern(ftp,'*.asp');
n := CkFtp2_GetDirCount(ftp);
if (n < 0) then
begin
Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
Exit;
end;
if (n > 0) then
begin
for i := 0 to n - 1 do
begin
// Display the filename
Memo1.Lines.Add(CkFtp2__getFilename(ftp,i));
// Display the file size (in bytes)
Memo1.Lines.Add(IntToStr(CkFtp2_GetSize(ftp,i)));
Memo1.Lines.Add('--');
end;
end;
success := CkFtp2_Disconnect(ftp);
CkFtp2_Dispose(ftp);
end;