Example 1 — List the Current Folder
Print the detailed list of files in the current remote directory.
<?php
$ftp = ftp_connect('ftp.example.com');
ftp_login($ftp, 'demo', 'secret');
ftp_pasv($ftp, true);
$lines = ftp_rawlist($ftp, '.');
foreach ($lines as $line) {
echo $line, PHP_EOL;
}
ftp_close($ftp); How It Works
- ftp_pasv() turns on passive mode so the listing works through most firewalls.
- ftp_rawlist() asks the server for a detailed list of the current folder.
- Each array item is one line, similar to the ls -l command.
- foreach prints every line so you can see permissions, size, date and name.

