<?php
/******************************************
*** SIMPLE FTP BACKUP FOR PERSONAL USE	*** 
*******************************************
***  Note: single-threaded connection   ***
******************************************/
/* Custom entries on lines:
   10, 11, 12, 28
   */

// ftp credentials
$ftp_server = "PUT YOUR FTP SERVER HERE";
$ftp_user = "PUT YOUR FTP USERNAME HERE";
$ftp_pass = "PUT YOUR FTP PASSWORD HERE";

// close connection first (can prevent some issues)
ftp_close($ftp_server);

// set up basic connection
$conn_id = ftp_connect($ftp_server); 

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass); 

// passive connection (can prevent some issues)
ftp_pasv($conn_id, true);

// change directory - go to dir where files are
ftp_chdir($conn_id, 'PUT YOUR FILES DIR HERE');

// the list with files from the ftp server
$file_list = ftp_nlist($conn_id, ".");

// filter out short values that are not valid:
// e.g. directories that are returned as . and ..
// the dirty way...
foreach ($file_list as $server_file) {
	if (strlen($server_file) < 2) {
		unset($server_file);
	}
	else {
		$local_file = $server_file;
		ftp_get($conn_id, $local_file, $server_file, FTP_BINARY);	
	}
}

// close the ftp stream 
ftp_close($conn_id);
?>