PHP FTP Synchronizer, update a website from a local content
Free program to update your website from local files. PHP FTP Synchronizer traverses the tree structure of the source directory recursively and updates the file on the website, by replacing the files which were modified.
PHP FTP Synchronizer is a script whose source code is in Scriptol language
and converted into PHP by the Scriptol PHP compiler available on this site,
in version 7.0.
It work at command line (a graphic interface is under development for Windows).
Why use PHP FTP Synchronizer?
Compared to the various existing programs, commercial for the majority, the synchronizer offers speed options:
- Possible use of a backup version on which the comparisons are performed, what avoids downloading the remote file and allows an extremely fast update thus. Moreover that builds a second backup of the site, possibly on a removable storage unit.
- Possibility of uploading all files modified in n last days, n being a number of days that you define.
Moreover the executable program is a PHP script, it thus works on all operating systems, Windows, Linux, Mac... And you can extend its possibilities if needed.
How the program works
The required parameters being given (see below), the program has the location
of your files, the name of the site (in ftp.xxxx.tld form), login and password,
directory on hosting if one does not copy at root, as well as chosen options.
It reads each file by scanning in a recursive way the source directory and the sub-directories, compares files with remote files if there exists, and copies them or replaces them.
If the option of acceleration is selected, it compares the dates or contents of file with the backup, and if they are different uploads the files, copies them on the backup also and synchronizes the date of files in the backup with that of sources.
The link checker is faster with curl and it also allows to check https links.
To set curl active, remove; before php_curl among extensions in php.ini.
To verify that this ini file is one that is taken into account, type:
This will give the path of the ini file loaded.
How to use the synchronizer
One opens a DOS Windows or a console under Linux or Mac.
Type this command:
php ftpsync.php [options]
Texts in brackets  are optional.
php ftpsync.php -v -llogin -ppassword -fftp.scriptol.com -dw:\scriptol\ -bf:\scriptol\ -wwww.scriptol.com
The options which are detailed in the handbook allow to pass all the required parameters. If a parameter misses, the program prompt you for it. But if an option is given and that must be followed by a string, this one must be provided in order, it is not asked by the program which in this case displays an error.
Last changes in versions
- 2.2. To come.
Support to curl to speed up the program.
Https links are recognized by the link checker.
- 2.1. June 3, 2016. Simplified the code.
- 2.0. March 30, 2015. Source code rewritten in Scriptol 2 and PHP code compatible with PHP 5.5.
- 1.9. February 13, 2012. Link checker now does not display 302 temporary redirects.
- 1.8 - September 20, 2010. Link checker now handles links relative to the root.
- 1.5 - August 6, 2008. The link check is differed, and performed once all pages are updated.
- 1.4 - July 1, 2008. Results of link check more precise. Only the pages with broken links or redirects are now displayed.
- 1.3 - June 24, 2008. The -u options activates a link check inside last added or modified pages.
- 1.2 - December 13, 2007. Added the -f option for url without ftp prefix.
- 1.1 - September 24, 2007. Added the passive FTP mode.
- 1.0 - September 18, 2007. First release.
- Without backup, after some times the program could accelerates and wants
to upload all the files without distinction.
That comes from a lack of memory for the PHP interpreter to make the comparisons and to select the modified files.
One can increase the allocated memory in the php.ini file which is in the Windows directory or equivalent under Unix just as the execution time granted to scripts:
max_execution_time = 3000 memory_limit = 256M
- It is possible also that the server closes the connection if it works for a long time. Use a backup directory or the -n option preferably.
- If you have installed Windows Live Oncare, ftp transferts are limited, verify first the results of updates made by the program before to use it in production.
Getting the program
The archive contains:
- The Scriptol source.
- The PHP executable script,
- The manual in HTML format, and ODF, you can create a PDF or Word's DOC file with Open Office.
- The ftpcheck script to verify a connection.
- The GPL licence.
By Kim Haskell & Denis Sureau . GNU GPL 2 License.
Link Checker on the server side
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)
set PATH=%PATH%;c:\PHP\This could be set automatically by the installer. Let me know if it works in the way or if you get error messages. For FAM, it is not part of the standard build, so I can not add it to the script that must run on any configuration. It must be added by the user.
php ftpsync.php -llogin -ppassword C:\xampp\htdocs\test ftp.xxxx.com -d/remotedir -bd:\backupdirlogin: the ftp login password: the ftppassword followed by the local directory ftp.xxxx.com the ftp URL remotedir the directory on the server, often htdocs or www d:\backupdir a drive and directory for a backup of the local image of the site, actually a backup of c:\xampp\htdocs\test
Entering Passive Mode
Warning: ftp_put (): Entering Passive Mode (x, x, x, x, x, x) .. in /home/ftpsync/ftpsync.php on line 215Can you help me understand what is happening? Thank you
max_execution_time = 3600The default of 30 seconds is not enough. Must be 3600 at least. No reason to limit locally the execution time!
memory_limit = 1024MThe default 128 mega seems enough, but actually this is often too small. Increase it to 1024M. This does suppress two reasons that impeach a script to run properly.