How to count number of files on a remote server that connected with FTP?
This is my code but it doesn't work
<?php
@$ftp = ftp_connect("host");
@ftp_login($ftp, "usr", "pwd");
ftp_chdir($ftp,'uploads/');
echo count(glob(ftp_pwd($ftp) . '*'));
?>
Thanks!
Try to use count()
and ftp_nlist()
functions combination:
$ftp = ftp_connect("host");
ftp_login($ftp, "usr", "pwd");
echo count(ftp_nlist($ftp, 'uploads/'));
ftp_close($ftp);
use ftp_rawlist :
$files = ftp_rawlist($ftp, '/');
echo count($files).' files ..';
instead of
echo count(glob(ftp_pwd($ftp) . '*'));
Try something like this
<?php
@$ftp = ftp_connect("host");
@ftp_login($ftp, "usr", "pwd");
//ftp_chdir($ftp,'uploads/');
//echo count(glob(ftp_pwd($ftp) . '*'));
if ($handle = opendir(ftp_chdir($ftp,'uploads/'))) {
while (($file = readdir($handle)) !== false){
if (!in_array($file, array('.', '..')) && !is_dir($dir.$file))
$i++;
}
}
echo "Total number of files:$i";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.