Hello,

I have folder on remote FTP server that is updated with more than XML file with different names in asynchronous (not scheduled time), I want to make a PHP application that fetch any new XML file arrives at the FTP automatically, so how can I make the PHP application fetching any XML file based on the arrival of XML file?

Thanks a lot.

Start with the PHP FTP manual.

Thanks already I know it, but I need to know how to synchronize between the FTP folder and PHP application, I need the PHP to fetch the XML file only when it arrives, how to do that mechanism?

Thanks.

You cannot get a message from the ftp server, but you can poll to see if there are new files (by fetching the rawlist). The only problem can be that a file is still being written the moment you access it.

OK, but you mean the PHP function (rawlist) will be executed periodically? What script shall I write to make the PHP application listens to the FTP server to see if there is new file added?

Please advise and thanks..

You'd need a PHP file that connects to the FTP server, retrieves the current folder list, and compare that with what you don't have. You can then schedule this script with cron, to run it at a given interval.

You'd need a PHP file that connects to the FTP server, retrieves the current folder list, and compare that with what you don't have. You can then schedule this script with cron, to run it at a given interval.

Thanks, so the idea is to make time scheduling, like to make the PHP application to check the folder every 5 mints?

One more question, do you have an example of the scheduling with cron in linux? I am not familiar with that command.

Thanks.

You can't. What you can do is compare the file sizes too. If they have changed since the last time then wait, otherwise retrieve the new file. This is still not fail proof since a file could be uploaded partially, aborted and then continued.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.