954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Fetch XML files on remote FTP Server based on XML file arrival

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.

Moderns
Junior Poster
105 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

Start with the PHP FTP manual .

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
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.

Moderns
Junior Poster
105 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

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.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

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..

Moderns
Junior Poster
105 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

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.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
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.

Moderns
Junior Poster
105 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

Right.

http://www.htmlcenter.com/blog/running-php-scripts-with-cron/

Probably your host provides you with cPanel, which should have an option to add cron items.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Right.

http://www.htmlcenter.com/blog/running-php-scripts-with-cron/

Probably your host provides you with cPanel, which should have an option to add cron items.


Thanks a lot.. I will read it and will implement it :) Appreciate your prompt action.

Moderns
Junior Poster
105 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

Right.

http://www.htmlcenter.com/blog/running-php-scripts-with-cron/

Probably your host provides you with cPanel, which should have an option to add cron items.


I got a question, how can we prevent from fetching incomplete XML file??

Moderns
Junior Poster
105 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

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.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: