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. It check for broken links in the page and update the sitemap.

PHP FTP Synchronizer is a script whose source code is writen in Scriptol language and compiled to PHP by the Scriptol 2 compiler available on this site.

Why use PHP FTP Synchronizer?

Compared to the various existing programs, commercial for the majority, the synchronizer offers speed options:

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.


Download PHP and unzip in a directory, for example: c:\php\

Under Windows add this directory to the PATH variable.

Type "env" in the search field on the task bar, select "path" and click on the modify button. Add this line:


In the php directory, rename the php.ini-production to php.ini

Add the ftp extension. Edit this php.ini file to remove ";" before ftp in the list of extensions.

Using curl

The link checker is faster with curl and it also allows to check https links.

To set curl active, remove ';' before curl among extensions in php.ini.
To verify that this ini file is one that is taken into account, type:

php --ini

This will give the path of the ini file loaded.

Memory limit

If the php writes that the memory is exhausted, you can change also the memory limit in the php.ini file.

memory_limit = 1024M  

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 -dw:\example\ -bf:\example\

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.

Program and manual

Manual of PHP FTP Synchronizer.

Download PHP FTP Synchronizer



Link Checker on the server side

2009-12-12 14:14:35


Is it possible to run the "Link Checker" script from a website? I uploaded the files to my server and tried to run linche.php, but here was an error: Warning: array_slice() [function.array-slice]: The first argument should be an array in /linche.php on line 429 I am quite new to programming. Chris
2009-12-14 03:10:02


The script is not designed to work on the server, there is no advantage to use it on the server because it accesses all the pages throught http:// About the error, it means that is variable is not an array because the script was not able to parse the page and returned false rather than an array.


2008-07-12 05:25:53


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.
2008-07-12 05:40:19


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.
2008-07-12 06:01:44


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.
2008-07-12 07:10:08


  if saved = 0
      print "Files compared by content"
      TOUCHFLAG = false
    TOUCHFLAG = touch(convertUnix(tempfile), time())
    if not QUIET 
      if TOUCHFLAG 
        print "Files compared by time"
        print "Touch failed, files compared by contents"
The 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
and the comparison of files too:
boolean filecompare(text a, text b)
return filemtime(a) > filemtime(b)
2008-07-12 12:52:14


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.
2008-07-14 11:37:09


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!


2011-05-30 04:55:44


Hello, First a question? How do i set sourcefolder to the parent relative to where the scripts are placed? ive tried ..\\test ../test ..\test /test \\test Without success. Im running XAMPP on windows. Also, i get these errors when running a sync. Strict Standards: Non-static method Path::merge() should not be called staticall y in C:\xampp\htdocs\filesync\ftpsync.php on line 367 Same on line 462. Thanks for a great script! Between, would it be possible to include FAM for your script? "fam_monitor_directory — Monitor a directory for changes" Thanks again! Kindest Regards, Mikael.
2011-05-30 07:02:02


Hello, You do not need for XAMPP to run the script. You must enter the directory of the script, usually /ftp and run it inside the directory. PHP must be installed and available anywhere. Under Windows, the path variable must be set to add the PHP directory. For exemple:
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.
2011-05-30 08:08:21


Thank you for your reply! It's the source folder to sync that im talking about. For example: php ftpsync.php -v test This would sync the folder test, that is in C:\xampp\htdocs\filesync\test But i need to sync the folder that's in C:\xampp\htdocs\test How would i write the command to point to that parent folder instead? PHP is in path and working properly, files are synced but i still get the error message, here is complete output: C:\xampp\htdocs\file-sync>php ftpsync.php -v test Verbose mode enabled Source directory: test Remote directory: Connected on localhost as ftp_user111 Passive mode turned on Synchronizing test on localhost PHP Strict Standards: Non-static method Path::merge() should not be called stat ically in C:\xampp\htdocs\file-sync\ftpsync.php on line 367 Strict Standards: Non-static method Path::merge() should not be called staticall y in C:\xampp\htdocs\file-sync\ftpsync.php on line 367 Processing test/test.txt PHP Strict Standards: Non-static method Path::merge() should not be called stat ically in C:\xampp\htdocs\file-sync\ftpsync.php on line 376 Strict Standards: Non-static method Path::merge() should not be called staticall y in C:\xampp\htdocs\file-sync\ftpsync.php on line 376 PHP Strict Standards: Non-static method Path::merge() should not be called stat ically in C:\xampp\htdocs\file-sync\ftpsync.php on line 462 Strict Standards: Non-static method Path::merge() should not be called staticall y in C:\xampp\htdocs\file-sync\ftpsync.php on line 462 0 file copied. Im using PHP version 5.3.5 CLI Using latest downloadable version of PHP FTP Synchronizer.
2011-05-30 10:41:42


The command should be:
php ftpsync.php -llogin -ppassword C:\xampp\htdocs\test -d/remotedir -bd:\backupdir
login: the ftp login password: the ftppassword followed by the local directory 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
2011-05-30 11:21:40


Thanks for the answer! Yes i know that works, but i need a relative path. Is that not possible?
2011-06-01 08:41:43


If the local image of the site is in the same directory that FTP synchronizer, you can omit the drive ie. c: and use just \xampp\htdocs\test Otherwise you must move the script on the same drive. The name of the directory is not important for the script.

Entering Passive Mode

2010-02-11 15:36:03


Hello, When I run ftpsync.php, everything goes well for about 15 seconds. Then a warning message appears and no more files uploaded. The following message appears: * I have hidden numbers
Warning: ftp_put (): Entering Passive Mode (x, x, x, x, x, x) .. in /home/ftpsync/ftpsync.php on line 215
Can you help me understand what is happening? Thank you
2010-02-12 12:36:35


Hello, Does the message appears after some files were uploaded, of before any file loaded? In the second case, the server could have disabled the passive mode. You can verify that with FreeFTP that uses the passive mode too. If it works with FreeFTP, the problem is elsewhere.
2010-02-15 07:34:48


The message appears after some files were upload. (and it's not the same numbrer each time) It works fine with FreeFTP... So, where do you think the problem is?
2010-02-15 12:52:37


Rather hard to anwser! I use it each day, sometimes with a very big lot of files and until an hour for checking all the external links in the file uploaded. It works fine for me, on several hosts. Unless I have more precisions, another error message, I can not know what happens. But you can change some PHP parameters in php.ini as this could has the effect you described:
max_execution_time = 3600
The default of 30 seconds is not enough. Must be 3600 at least. No reason to limit locally the execution time!
memory_limit = 1024M
The 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.