Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Get FTP Directory Listing Filenames and Sizes
Fetch FTP directory filename and size information. // Get file and directory information for a remote FTP directory.
procedure TForm1.Button6Click(Sender: TObject);
var
success: Integer;
n: Integer;
i: Integer;
fsize: Integer;
fname: WideString;
isDir: boolean;
begin
// Import the Chilkat FTP-2 ActiveX control into Delphi and then
// drop an instance of the FTP control onto the form.
// Unlock once at the beginning of your program.
ChilkatFtp21.UnlockComponent('anything for 30-day trial');
ChilkatFtp21.Hostname := 'ftp.chilkatsoft.com';
ChilkatFtp21.Username := '***';
ChilkatFtp21.Password := '***';
// Connect to the server
success := ChilkatFtp21.Connect();
if (success = 1) then
begin
// Set a list pattern to get all the files in the current remote directory,
// which is our login's home directory immediately after connecting.
ChilkatFtp21.ListPattern := '*';
n := ChilkatFtp21.NumFilesAndDirs;
for i := 0 to n-1 do begin
fsize := ChilkatFtp21.GetSize(i);
fname := ChilkatFtp21.GetFilename(i);
isDir := (ChilkatFtp21.GetIsDirectory(i) = 1);
if (isDir) then
Memo1.Lines.Add('DIR: ' + fname + ' ' + IntToStr(fsize) + ' bytes')
else
Memo1.Lines.Add(fname + ' ' + IntToStr(fsize) + ' bytes');
end;
end
else
begin
ChilkatFtp21.SaveLastError('ftpConnectError.txt');
if (ChilkatFtp21.ConnectVerified = 1) then
ShowMessage('Login error. Check your username/password')
else
ShowMessage('Cannot connect to FTP server');
end;
end;
|
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.