[英]PHP - What is the best practice for getting the ftp list from the remote server?
What is the best practice for getting the ftp file list from the remote server? 从远程服务器获取ftp文件列表的最佳实践是什么?
1) Using ftp_connect() function 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);
?>
or 要么
2) Using scandir() and then output the file list with print_r() 2)使用scandir(),然后使用print_r()输出文件列表
<?php
$path = "ftp://login:password@ftpserver";
$files = scandir($path);
print_r($files);
?>
Both methods output an array with ftp directories/files. 两种方法都输出带有ftp目录/文件的数组。
My opinion is that first one is preferable, why: 我认为第一个是可取的,为什么:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.