I'm trying to create a php file that I can use with cron to transfer a file from an ftp server to my site every day. It is a real estate site and the file contains information from the local MultiList Service.
My difficulty is that the filename changes daily, thankfully within a set of parameters. The beginning letters "MF" and the ending letters "RESN001.zip" are constant, the middle of the filename changes by date and time. The time element is not standard, varying daily.
Here is what I've been able to do so far:
Download the file by setting the filename manually:
$local_file = "xxx.zip";
$server_file = "MFxxxxxxxxxxRESN001.zip;
$ret=ftp_get($conn_id, $local_file, $server_file, FTP_BINARY) or die ('Could not download: ' . mysql_error());
echo "Successfully written to $local_file\n";
Get the filename as part of an array (it is the only record in the array):
$contents = ftp_nlist($conn_id, "./MF*RESN001.zip");
var_dump($contents);
What I'm looking for is a way to cross these 2 pieces of information so I can set the $server_file to download the file name returned in the $contents variable. I'm having trouble because it is returned as an array rather than a string.
The second part of the question is, can (and how) do I handle having multiple file names in the array. I would like to download all of the files returned by a search (i.e. MFxxxxxxRESN001.zip, MFxxxxxxRESN002.zip, and MFxxxxxxRESN003.zip.)
I do want to have both options available if possible. (A single filename array or multiple filename array, though I guess the number of files in the array shouldn't matter. If it does 3, it will do 1.)
Thanks!