I have developed a recursive FTP-download script, in PHP5, that allows you to select some files and/or directories to download using an AJAX request. The POST-variable that the server receives is just a short pipe-separated string that does not take up any memory at all.

The script itself works perfectly on my local Apache setup and goes into each directory and downloads every single file and folder.

On my remote virtual server which is set up under Media Temple the script fails on large structures, that is handled great by my local Apache.

The symptoms is that some directories are considered to be files and therefore the script won't step into them and download further.

The script checks whether or not a path is a directory by trying to open it remotely. If it can open the directory it recursively downloads everything in it until it finishes.

The php.ini that is hosted on Media Temple has a much higher threshold than the one on my local setup (longer max execution time, higher memory limit etc.) so that's not the issue... I have even tried using my local php.ini on the remote server.

Tailing the error log used to get my "Premature end of script headers, PHP" until I switched to a dedicated virtual server from regular hosting. Now it doesn't react at all.

What I've tried to solve the issue is experimenting with different values in php.ini and most recently I did a flush() and ob_flush() for every new file and directory that was created... in an attempt to stop any occurance of "Premature end of script headers, PHP".

Do you have any ideas?

Comments

Just a suggestion ... a polite question doesn't start with 'Hey!' -- apart from that, is it wise to check whether an object is a file or folder by trying to open it?

Written by pavium

Sorry for the "Hey!" :) No, it doesn't feel very good. However, there is no other way (as far as I know) to check whether or not it is a dir... There's no is_dir() function for FTP. What I did before was to check for dots in the last segment of the filename. But a directory can contain dots so it was a bad idea. This is sloweer but gives a correct result.

Written by Christoffer

Accepted Answer

Well basicly i don't know how your code is looking like, but that part here (from the php.net maillinglist) is working fine on my server. Maybee you can give us an example of your code?

Written by Dennis
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki