2015-04-16 73 views
0

我需要從我的FTP服務器中使用PHP獲取所有.ch文件(位於特定文件夾內)到我的網站。我可以收到一些關於我該怎麼做的指導?從FTP獲取所有.ch文件到網站

+0

FTP和HTTP是在同一臺服務器上或在不同的服務器上.CH? –

回答

0

從PHP手冊閱讀這些basic examples後,您可以使用此代碼的部分:

<?php 
$dir = "/ftpdir/source/"; 
$dir1= "/websitedir/newfolder/" 

// Open a directory, and read its contents 
if (is_dir($dir)){ 
    if ($dh = opendir($dir)){ 
    while (($file = readdir($dh)) !== false){ 
     //Check the file extension, several methods available 
     $ext=pathinfo($dir.$file); 
     // If the extension is ch, then copy the file 
     if($ext == "ch") { 
      if(copy($dir.$file,$dir1.$file)) { 
         echo $dir.$file." has been copied to ".$dir1.$file."<br>"; 
       } 
      else { echo "Something went wrong.<br>"; } 
      } 
    } 
    closedir($dh); 
    } 
} 
?> 

我希望這會幫助你。

0

請檢查:http://php.net/manual/en/function.ftp-nlist.php

例子:

<?php 

// set up basic connection 
$conn_id = ftp_connect($ftp_server); 

// login with username and password 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

// get contents of the current directory 
$contents = ftp_nlist($conn_id, "."); 

// output $contents 
var_dump($contents); 

?> 

你可以很容易將此使用if($something == "ch") {...}