[英]Getting a list of directories and files from root directory from remote site via FTP using CURL and PHP
[英]PHP - What is the best practice for getting the ftp list from the remote server?
從遠程服務器獲取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目錄/文件的數組。
我認為第一個是可取的,為什么:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.