ftp_rawlist()函數是PHP中的一個內置函數,該函數返回具有諸如權限等信息的文件列表,最後一次從遠程服務器(即FTP服務器)上的指定目錄中修改了文件。
用法:
ftp_rawlist( $ftp_connection, $directory, $recursive )
參數:此函數接受上述和以下所述的三個參數:
- $ftp_connection:它是必填參數。它指定已經存在的FTP連接。
 - $directory:它是必填參數。它指定遠程服務器(即FTP服務器)中要檢索其文件信息的目錄的路徑。 “ ./”用於當前目錄,“ ../”用於當前目錄的父目錄。它可能包含LIST命令的參數。
 - $recursive:它是可選參數。它指定是要發送到服務器的LIST還是LIST -R命令。如果設置為TRUE,則發送LIST -R命令。默認情況下,它發送LIST命令。
 
返回值:
- 成功時:它返回一個數組,其每個元素對應於一行文本。
 - 失敗時:它返回FALSE。以防傳遞無效目錄時。
 
注意:
- 此函數可用於PHP 4.0.0和更高版本。
 - 以下示例無法在在線IDE上運行。因此,請嘗試使用適當的ftp服務器名稱在某些PHP托管服務器或localhost中運行。
 
例:
<?php 
  
// Connect to FTP server 
  
// Use a correct ftp server 
$ftp_server = "localhost"; 
  
// Use correct ftp username 
$ftp_username = "username"; 
  
// Use correct ftp password corresponding 
// to the ftp username 
$ftp_userpass = "password"; 
   
// Establishing ftp connection  
$ftp_connection = ftp_connect($ftp_server)  
        or die("Could not connect to $ftp_server"); 
  
if($ftp_connection) { 
    echo "successfully connected to the ftp server!"; 
      
    // Logging in to established connection with 
    // ftp username password 
    $login = ftp_login($ftp_connection, 
            $ftp_username, $ftp_userpass); 
      
    if($login) { 
          
        // Checking whether logged in successfully 
        // or not 
        echo "<br>logged in successfully!"; 
          
        // Storing  data in $file_list 
        $file_list = ftp_rawlist($ftp_connection, "/"); 
          
        // Printing raw array with print_r() 
        print_r($file_list); 
    } 
    else { 
        echo "<br>login failed!"; 
    } 
      
    // Closeing  connection 
    if(ftp_close($ftp_connection)) { 
        echo "<br>Connection closed Successfully!"; 
    }  
} 
?>輸出:

參考: https://www.php.net/manual/en/function.ftp-rawlist.php
相關用法
- p5.js nfc()用法及代碼示例
 - p5.js nfp()用法及代碼示例
 - d3.js d3.hcl()用法及代碼示例
 - p5.js nfs()用法及代碼示例
 - PHP cos( )用法及代碼示例
 - PHP sin( )用法及代碼示例
 - p5.js nf()用法及代碼示例
 - PHP tan( )用法及代碼示例
 - PHP pow( )用法及代碼示例
 - d3.js d3.map.set()用法及代碼示例
 - d3.js d3.set.has()用法及代碼示例
 - PHP Ds\Set xor()用法及代碼示例
 
注:本文由純淨天空篩選整理自gekcho大神的英文原創作品 PHP | ftp_rawlist() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
