PHP
Chilkat2 PHP
Get Filenames in a Remote Directory
Gets the names of files in a remote FTP directory.Chilkat PHP Downloads
<?php
use Chilkat2\Ftp2;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$ftp = new Ftp2();
$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.
try {
$ftp->Connect();
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Iterate over .txt files.
$ftp->ListPattern = '*.txt';
$n = $ftp->GetDirCount();
echo 'n = ', $n, "\n";
$i = 0;
while ($i < $n) {
echo $i, ': ', $ftp->GetFilename($i), "\n";
$i = $i + 1;
}