phpftpcopy

How to copy all files from FTP that start with same string using PHP


How can I copy all the files from FTP, that start with same string, using PHP? I can copy one file, using this code:

if (copy('ftp://testuser:pass@ftpserver/file_20240520170720.MIS','file.MIS')) {
  echo "It worked!!!";
}

but I need to copy all the files that start with string file_20240520.


Solution


  • For an inspiration, a similar question that selects files to download based on a timestamp (rather than a file name):
    Downloading only new images from FTP server in PHP