├── LICENSE ├── README.md └── index.php /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PHP sync local folder to remote ftp folder 2 | ============================= 3 | 4 | PHP script for sync local folder to remote FTP server 5 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | "; 16 | syncFolderToFtp($host, $username, $password, $remote_backup, $backup_folder); 17 | echo ""; 18 | 19 | // Functions 20 | function syncFolderToFtp($host, $username, $password, $remote_backup, $backup_folder) { 21 | $ftp = ftp_connect($host); // connect to the ftp server 22 | ftp_login($ftp, $username, $password); // login to the ftp server 23 | ftp_chdir($ftp, $remote_backup); // cd into the remote backup folder 24 | 25 | // copy files from folder to remote folder 26 | $files = glob($backup_folder . '*'); 27 | $c = 0; 28 | $allc = count($files); 29 | foreach($files as $file) { 30 | $c++; 31 | 32 | $file_name = basename($file); 33 | echo "\n $c/$allc: $file_name"; 34 | 35 | $upload = ftp_nb_put($ftp, $file_name, $file, FTP_BINARY); // non-blocking put, uploads the local backup onto the remote server 36 | while ($upload == FTP_MOREDATA) { 37 | // Continue uploading... 38 | $upload = ftp_nb_continue($ftp); 39 | } 40 | if($upload != FTP_FINISHED) { 41 | echo " ... ERROR"; 42 | }else{ 43 | echo " ... OK"; 44 | } 45 | } 46 | 47 | ftp_close($ftp); // closes the connection 48 | } 49 | ?> 50 | --------------------------------------------------------------------------------