簡體   English   中英

PHP-從遠程服務器獲取ftp列表的最佳實踐是什么?

[英]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目錄/文件的數組。

我認為第一個是可取的,為什么:

  1. 它清楚地表明它是ftp連接,這意味着您不僅可以將其用於列出文件,還可以在以后需要時用於上傳,還可以正確處理錯誤並提供更好的錯誤消息或日志記錄
  2. 第二種方法依賴allow_url_fopen設置,由於可能存在安全漏洞,最好禁用它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM