I am trying to get the csv files from from different folders on FTP recursiverly, but getting an error while trying to download, I searched most of the questions but not releavent to the situation where I am struck.
FTP: csv file location
/home/lanein1/ftpfiles/AIN/2021-07-14/AIN.csv
/home/lanein1/ftpfiles/AOUT/2021-07-14/AOUT.csv
/home/lanein1/ftpfiles/BIN/2021-07-14/BIN.csv
/home/lanein1/ftpfiles/AOUT/2021-07-14/BOUT.csv
I can get to the directory ftpfiles and do a pregmatch , but I am getting Invalid argument supplied foreach()
Code:
$login_result = ftp_login($con, usr,pwd);
ftp_pasv($con, true);
basedir = /home/lanein1/ftpfiles/ --- this is were i am stuck to pass the different folders
$path = 'basedir'.date('Y.m.d',strtotime("-1 days"));
$files = ftp_nlist($con,$path);
{
foreach ($files as $file)
{
if (preg_match("/\.csv$/i", $file))
{
echo" Found $file\n";
ftp_get($con, $file, FTP_BINARY);
}
else
{
echo "not Found";
}
}
ftp_close($con);