略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ftp_mlsd

2024-05-07

ftp_mlsd

(PHP 7 >= 7.2.0, PHP 8)

ftp_mlsd返回指定目录中的文件列表

说明

ftp_mlsd(resource $ftp, string $directory): array|false

参数

ftp

FTP 连接的链接标识符。

directory

要列出的目录。

返回值

如果成功,则返回一个由目录中所有文件信息(数组)所组成的数组; 如果错误,则返回 false

范例

示例 #1 ftp_mlsd() 示例

<?php

// 简单基本连接
$conn_id ftp_connect($ftp_server);

// 使用用户名和密码进行登录
$login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass);

// 获取当前目录的内容
$contents ftp_mlsd($conn_id".");

// 输出 $contents
var_dump($contents);

?>

以上例程的输出类似于:

array(5) {
  [0]=>
  array(8) {
    ["name"]=>
    string(1) "."
    ["modify"]=>
    string(14) "20171212154511"
    ["perm"]=>
    string(7) "flcdmpe"
    ["type"]=>
    string(4) "cdir"
    ["unique"]=>
    string(11) "811U5740002"
    ["UNIX.group"]=>
    string(2) "33"
    ["UNIX.mode"]=>
    string(4) "0755"
    ["UNIX.owner"]=>
    string(2) "33"
  }
  [1]=>
  array(8) {
    ["name"]=>
    string(2) ".."
    ["modify"]=>
    string(14) "20171212154511"
    ["perm"]=>
    string(7) "flcdmpe"
    ["type"]=>
    string(4) "pdir"
    ["unique"]=>
    string(11) "811U5740002"
    ["UNIX.group"]=>
    string(2) "33"
    ["UNIX.mode"]=>
    string(4) "0755"
    ["UNIX.owner"]=>
    string(2) "33"
  }
  [2]=>
  array(8) {
    ["name"]=>
    string(11) "public_html"
    ["modify"]=>
    string(14) "20171211171525"
    ["perm"]=>
    string(7) "flcdmpe"
    ["type"]=>
    string(3) "dir"
    ["unique"]=>
    string(11) "811U5740525"
    ["UNIX.group"]=>
    string(2) "33"
    ["UNIX.mode"]=>
    string(4) "0755"
    ["UNIX.owner"]=>
    string(2) "33"
  }
  [3]=>
  array(8) {
    ["name"]=>
    string(10) "public_ftp"
    ["modify"]=>
    string(14) "20171211174536"
    ["perm"]=>
    string(7) "flcdmpe"
    ["type"]=>
    string(3) "dir"
    ["unique"]=>
    string(11) "811U57405EE"
    ["UNIX.group"]=>
    string(2) "33"
    ["UNIX.mode"]=>
    string(4) "0755"
    ["UNIX.owner"]=>
    string(2) "33"
  }
  [4]=>
  array(8) {
    ["name"]=>
    string(3) "www"
    ["modify"]=>
    string(14) "www"
    ["perm"]=>
    string(7) "flcdmpe"
    ["type"]=>
    string(3) "dir"
    ["unique"]=>
    string(11) "811U5740780"
    ["UNIX.group"]=>
    string(2) "33"
    ["UNIX.mode"]=>
    string(4) "0755"
    ["UNIX.owner"]=>
    string(2) "33"
  }
}

参见

add a noteadd a note

User Contributed Notes 1 note

up
0
fantastory dot net at gmail dot com
1 year ago
When running from script the function may require ftp_pasv, for swithching server to pasive mode.

If you are behind firewall ftp_mlsd will return FALSE otherwise.

官方地址:https://www.php.net/manual/en/function.ftp-mlsd.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3