2015/01/09

在CentOS 6.5 透過PHP取得Ftp檔案列表

<?php

 $conn = ftp_connect("host", 21, 300);

 if($conn){

  $login = ftp_login($conn, 'username', 'password');
  
  if($login){
   echo "true<br/>";
   $list = ftp_nlist($conn, ".");

   $count = count($list);

   if($count == 0){
    echo "No such file.<br/>";
   }else{
    foreach ($list as $file) {
     echo $file . "<br/>";
    }
   }
  }else{
   echo "error<br/>";
  }

  ftp_close($conn);
 }else{
  echo "error<br/>";
 }

?>


#記得加上這幾個權限
setsebool httpd_can_network_connect on
setsebool ftp_home_dir on