如何从远程服务器获取ftp文件列表的最佳实践?
1)使用ftp_connect()函数
<?php
// set up connection
$conn = ftp_connect($ftp_server);
// login with username and password
$login = ftp_login($conn, $ftp_user_name, $ftp_user_pass);
// get contents of the current directory
$content = ftp_nlist($conn, ".");
// output content
var_dump($content);
?>
或者
2) 使用scandir()函数,然后用print_r()输出文件列表。
<?php
$path = "ftp://login:password@ftpserver";
$files = scandir($path);
print_r($files);
?>
这两种方法都会输出一个包含ftp目录/文件的数组。