How to download all files and folders via FTP in PHP

If you want to write a simple FTP client using PHP script which will download all the files and folders from your website then the following script is just what you need. The function uses recursion to download the files and folders from your website and creates the exact image of the website on your computer.

You just need to enter the server address, username and password below and run the PHP script.

$ftp_server = "";
$ftp_user = "";
$ftp_pass = "";

$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

function get_file($strDir) {
	global $conn_id;
	$contents = ftp_nlist($conn_id, $strDir);	
	for($i=0; $i";
			} else {
				echo "There was a problem ".substr($contents[$i],1)."
"; } } else { mkdir(substr($contents[$i],1),0777,true); $a = get_file($contents[$i]); } } return 1; } if (ftp_login($conn_id, $ftp_user, $ftp_pass)) { $contents = ftp_nlist($conn_id, "."); for($i=0; $i"; mkdir($contents[$i]); $a = get_file("/". $contents[$i]); } } }
Please follow and like us:
error

5 Comments

Leave a Reply

Your email address will not be published.