Listing a remote folder's contents (Delphi example)
In This Topic
This example demonstrates the 8 following steps for listing files with the ListFolderContents method:
Specify the FTP server's address
Specify the username to login
Specify the password for the username
Connect to the FTP server
Begin the listing process
Process each item being listed
Disconnect from the FTP server
Perform error handling
The following code assumes you have placed an XceedFtp control and a Listbox on a form and have called them 'XceedFtp1' and 'Listbox1' respectively (the default names).
The first section of code below demonstrates all steps except step (6). Step (6), the handler for the ListingFolderItem event, is found right after.
try {step (8)} XceedFtp1.Connect(); {step (4)} ShowMessage('Successfully connected to server. Starting the listing of the contents of the current folder.');
try {step (8)} XceedFtp1.ListFolderContents(''); {step (5)} except on xErr: Exception do ShowMessage('Error while listing. Description: ' + xErr.Message) end;
try {step (8)} XceedFtp1.Disconnect(); {step (7)} except on xErr: Exception do ShowMessage('Error while disconnecting. Description: ' + xErr.Message) end;
except on xErr: Exception do ShowMessage('Error while connecting. Description: ' + xErr.Message) end; end;
{ Step (6): The following code which adds the name and size of each item being listed into a listbox on your form) must go into the error handler for the ListingFolderItem event.}