正在将 FTP 中的所有 .ch 文件提取到网站中

Fetching all .ch files from FTP into website

我需要使用 PHP 从我的 FTP 服务器将所有 .ch 文件(位于特定文件夹内)提取到我的网站中。我可以收到一些关于如何操作的指导吗?

阅读 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); 
  } 
} 
?> 

希望对您有所帮助。

请检查: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") {...}

轻松将其应用于 .ch