The following code will list all files in a remote directory. I have a remote directory consisting of jpg and txt files. But I need to list only the txt files.
I tried adding:
if(eregi('.txt', $file)){
echo "<br>$file";
}
within foreach, but it wouldn't work.
<?php
$ftp_server = 'ftp.server.net';
$ftp_user_name = 'user';
$ftp_user_pass = 'pass';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// get contents of the current directory
$file_list = ftp_nlist($conn_id, "");
foreach ($file_list as $file)
{
echo "<br>$file";
}
// close the connection
if ($conn_id) {
ftp_close($conn_id);
}
?>