Copy Code code as follows: 
 
 
  
 
 
/* 
 
When you use Ftp_nlist (), the returned array value can be of two types: varies by server 
 
A: Separate file names 
 
B: Contains the file name of the directory. 
 
If misappropriated, please note change here. 
 
*/ 
 
<?php 
 
function Download_file ($dir, $FC, $_file_) 
 
{ 
 
$fn =ftp_nlist ($FC, "."); /Lists the file name (including subdirectories) of the directory, stored in the array 
 
$size =sizeof ($FN); 
 
$dir = ($dir = = "") $dir:('/'. $dir); 
 
$_file_=$_file_. $dir; 
 
echo $_file_. " <br/> "; 
 
for ($i =0; $i < $size; $i + +) 
 
{ 
 
if (Ereg (' ^[a-za-z0-9_]+ ', $FN [$i]))//extract is file and directory, culling.,.. The two directories 
 
{ 
 
if (Ereg (' ^[a-za-z0-9_]+ ([a-za-z0-9-]*.*) (\.+) ', $FN [$i]))//is a file to download directly 
 
{ 
 
if (Ftp_get ($FC, $fn [$i], $FN [$i],ftp_binary)) 
 
{ 
 
echo "<br/> download". GETCWD (). " /". $FN [$i]." Success <br/> "; 
 
} 
 
Else 
 
{ 
 
echo "<br/> download". GETCWD (). " /". $FN [$i]." Failure <br/> "; 
 
} 
 
}//File Download complete 
 
else//"is the directory, access the directory, and then read the file"; 
 
{ 
 
if (!file_exists ($FN [$i])) 
 
mkdir ($fn [$i], 0700)//The directory does not exist on the local machine to create a 
 
if (Ftp_chdir ($FC, $FN [$i]) 
 
ChDir ($fn [$i]); 
 
echo "The current directory is:". GETCWD (). <br/> "//better see the current directory 
 
Download_file ($fn [$i], $FC, $_file_);//recursively enter the directory to download the file 
 
} 
 
}//extract files, end of directory 
 
}//for Loop End 
 
Ftp_cdup ($FC);//ftp server returns upper Directory 
 
ChDir (DirName ($_file_)); 
 
}//download--file () function ends 
 
$_file_= "Local Machine absolute address";//For example C:/download, don't do this c:/download/ 
 
$hostname = "server name"; 
 
$loginname = "User name"; 
 
$password = "User password"; 
 
$FC =ftp_connect ($hostname, "a") or Die ("couldn ' t connect to $hostname"); 
 
$FC _rw=ftp_login ($FC, $loginname, $password); 
 
Ftp_set_option ($FC, ftp_timeout_sec,100000);/Set timeout time 
 
$dir = ""; ChDir ($_file_);//Enter Local machine absolute address directory 
 
Download_file ($dir, $FC, $_file_); 
 
Ftp_quit ($FC); 
 
Programs that download the file tree from the server 
 
?> 
 
 
 
Hope to bring you help, thank you