PHP FTP Synchronizer and download
Hi, First of all I'd like to say a big 'Thank you' for writing the solution to my problem. The PHP FTP Synchronizer has saved me hours of work and I wish I'd found it months ago. I would like to ask 2 questions if I may? 1. Can it script be reversed to download instead of upload? 2. Can I set the script to only download/upload if the date and time is newer? Hope you can help.
Hello. Download rather that upload will change the logic of the program. I suppose you want to create or to modify articles online and save the changes locally. In this case, the backup directory is useless and you need to compare the date and time, indeed. By default, the program compares the date/time but for my personal use, I prefer to compare the content for efficiency. I have not tried this solution yet, but I suppose that if the PHP FTP Synchronizer script is stored on the server, and that the local site is treated as a distant site, the program could work with some configuration prerequisites. The other solution is to rewrite the script to invert the process. Not very difficult, but requires some work however. If there is heavy demand, we could consider to do it, but in all case, contributions are welcomed.
That's grand. Basically, I have a server that produces News content and about 120 PC's around the UK showing this content in shop windows and etc. I am currently pushing this content from the server to all the PC's in turn (which is okay). I have just picked up a new contract for a further 250 PC's and I would prefer a P2P model on each client PC that looks at the server for a list of peers (IP addresses) and then randomly picks one and then does 'The Sync'. All is complete altough instead of downloading the content, it uploads it. Although I would not want you to spend time for just my solution, I still really need to manipulate the script to work in the environment that I have. When the script compares the remote and local files does it look at the date/time stamp? If so, where abouts in the script does this take place? Thanks in advance. Jason.
if saved = 0 backError(bpath) else if CONTFLAG print "Files compared by content" TOUCHFLAG = false return /if TOUCHFLAG = touch(convertUnix(tempfile), time()) unlink(tempfile) if not QUIET if TOUCHFLAG print "Files compared by time" else print "Touch failed, files compared by contents" /if /if /ifThe CONTFLAG bypasses a code that perfoms a kind of comparison by time. I just realized that she has performed the comparison on a temp file. To solve your problem, you should compare the time for the remote file with the filemtime() function that works with some protocols, according to the PHP doc. Unfortunally, not all servers support this feature. You have to test the result on your server first:
echo filemtime(some url);and this function has to be updated:
void checkRemote(text rpath) TOUCHFLAG = filemtime(rpath) != false returnand the comparison of files too:
boolean filecompare(text a, text b) return filemtime(a) > filemtime(b)
This is just getting better. I can now compare both remote and local files with 'filemtime' and flag it depending on the result. Here's a question... As stated earlier, I would like to FTP_GET instead of FTP_PUT but I know it will be a problem when I have to list all the remote files into an array. And when there is approximatly 29k files it's gonna take ages!!! Yeah, I know FTP_PUT would be easier, but I have to push files to one host at a time and FTP_GET can run on each client and would update quicker. Do I: 1. FTP_NLIST (could be slower as stated above)? or as each client runs PHP and it's own public webserver: 2. Throw it an external command to reply with an XML of files and their dates? Or do you think another way would be better? Don't forget it's Saturday night!!! Have a good one, Jason.
Sorry, but we have not experienced none of these methods for now... Probably you have a better experience about this subject than us at this stage!