I have a script which connects to an external ftp server and downloads the contents of a folder.
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?
My script is (which works 100%):
$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 "<br><font color=blue><b>Import into LOC MySQL.....</b></font><br>";
// 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. <br>";
Thanks as always for the assistance,
Try this: