PHP 8.3.4 Released!

ftp_mlsd

(PHP 7 >= 7.2.0, PHP 8)

ftp_mlsdディレクトリに存在するファイルの一覧を返す

説明

ftp_mlsd(FTP\Connection $ftp, string $directory): array|false

パラメータ

ftp

FTP\Connection クラスのインスタンス

directory

ファイルの一覧を得るディレクトリ

戻り値

成功したときは、指定されたディレクトリに存在するファイル情報を配列で返します。 エラーのときは false を返します。

変更履歴

バージョン 説明
8.1.0 引数 ftp は、FTP\Connection のインスタンスを期待するようになりました。 これより前のバージョンでは、リソース を期待していました。

例1 ftp_mlsd() の例

<?php

// 基本的な接続のセットアップ
$ftp = ftp_connect($ftp_server);

// ユーザー名とパスワードでログイン
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);

// 現在のディレクトリの内容を取得
$contents = ftp_mlsd($ftp, ".");

// $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"
  }
}

参考

  • ftp_rawlist() - 指定したディレクトリの詳細なファイル一覧を返す
  • ftp_nlist() - 指定したディレクトリのファイルの一覧を返す

add a note

User Contributed Notes 3 notes

up
2
fantastory dot net at gmail dot com
3 years 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.
up
1
Frank Glck
1 year ago
sometimes it is necessary to set:

ftp_set_option($this->connection_id, FTP_USEPASVADDRESS, false)

before you set:
ftp_pasv($this->connection_id, $state)
up
0
andy at sarver dot pro
11 months ago
I have yet to find a resolution to this; but I notice the ftp_mlsd command is limited in the number of files it will grab at once. For me it ranged between 7,500 and 8,500 files. Seems to me there is some max duration it will query for and what you get is a function of how fast the files can be enumerated.
To Top