title: download only .csv files from external FTP server to my ftp server
body: <p>I have a script which connects to an external ftp server and downloads the contents of a folder.</p>
  
  <p>Currently it will download all files in the folder. How can I modify the below script to only download and process .csv files and ignore any other files?</p>
  
  <p>My script is (which works 100%):</p>
  
  <pre><code>$timenow=time();
  $ftp_server = "ftp.domain.com";  
  $conn_id = ftp_connect($ftp_server);  
  $ftp_user_name = "username";  
  $ftp_user_pass = "password";  
  $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);  
  $contents = ftp_nlist($conn_id, 'LoadsOverWB'); 
  $targetnameprocesses ="LoadsOverWB-$timenow.csv";
  
  
  $filename = $contents[0]; 
  
  echo "&lt;br&gt;&lt;font color=blue&gt;&lt;b&gt;Import into LOC MySQL.....&lt;/b&gt;&lt;/font&gt;&lt;br&gt;";
  // import file
  if ((empty($filename))) { echo "$filename not existing to import.";} else {
  $source = "LoadsOverWB/$filename";
   $target = fopen("$filename", "w");
  
  $conn = ftp_connect("ftp.hulamin.co.za") or die("Could not connect");
   ftp_login($conn,"TransportLogistics","Qaz1234");
  
  ftp_fget($conn,$target,$source,FTP_ASCII);
  
  echo "file downloaded. &lt;br&gt;";
  </code></pre>
  
  <p>Thanks as always for the assistance,</p>