PHP FTP recursive directory listing

前端 未结 3 486
轻奢々
轻奢々 2020-12-10 09:12

I\'m trying to make a recursive function to get all the directories and sub directories from my ftp server in an array.

I tried a lot of functions I\'ve found on the

3条回答
  •  温柔的废话
    2020-12-10 10:00

    I've build an OOP FTP Client library that's can help you on this a lot, using just this code you can retrieve a list of only the directories with addition useful information like (chmod, last modified time, size ...).

    The code :

    // Connection
    $connection = new FtpConnection("localhost", "foo", "12345");
    $connection->open();
            
    // FtpConfig
    $config = new FtpConfig($connection);
    $config->setPassive(true);
    
    $client = new FtpClient($connection);
    
    $allFolders =
        // directory, recursive, filter
        $client->listDirectoryDetails('/', true, FtpClient::DIR_TYPE); 
    
    // Do whatever you want with the folders
    

提交回复
热议问题