/*******************************************************************************/
/* WEB SITE COPIER */
/* PROGRAMMER : */
/* Benediktus Ardian Hersanto */
/*******************************************************************************/
GLOBAL $host,$username,$pswd,$dir,$action,$todir,$fulldir;
$img_type = array ("jpg","JPG","gif","GIF","png","PNG","jpeg","JPEG","swf","SWF","mov","MOV","mp3","MP3","mid","MID");
$doc_type = array ("htm","HTM","html","HTML","txt","TXT","dat","DAT","xml","XML","pl","PL","cgi","CGI","php","PHP","phtml","PHTML","php3","PHP3");
$frontpage = array ("_derived","_fpclass","_overlay","_private","_themes","_vti_cnf","_vti_log","_vti_txt","_vti_bin","_vti_pvt","_vti_inf");
if ($action == "copy") {
// Connect to source ftp server
$status = ftp_connect($host,21);
if (!$status) { die ("
FTP CONNECTION FAILED TO $host
"); }
$login = ftp_login ($status,$username,$pswd);
if (!$login) { die ("Username or Password not accepted on host $host
"); }
$dirlist = ftp_nlist ($status,$dir);
if (!$dirlist) { die ("Cannot read directory $dir on host $host
"); }
foreach ($dirlist as $eachfile) {
$slash = explode($dir."/",$eachfile);
$ext = explode(".",$slash[1]);
if ($todir == "") {
$fulldir = $slash[1];
} else {
$fulldir = $todir."/".$slash[1];
}
if (($ext[0] != "") && ($ext[1] != "")) {
if (in_array($ext[1],$img_type)) {
$getstatus = ftp_get($status, $slash[1], $eachfile, FTP_BINARY);
if (!$getstatus) { print "Unknown Error while retrieving file $slash[1]
"; }
if ($todir != "") {
system("mv $slash[1] $todir");
}
print "Copying binary file $slash[1] from $host$eachfile
";
}
if (in_array($ext[1],$doc_type)) {
$getstatus = ftp_get($status, $slash[1], $eachfile, FTP_ASCII);
if (!$getstatus) { print "Unknown Error while retrieving file $slash[1]
"; }
if ($todir != "") {
system("mv $slash[1] $todir");
}
print "Copying document $slash[1] from $host$eachfile
";
}
} else {
if (in_array($slash[1],$frontpage)) {
print "Passing Frontpage ekstention directory \"$slash[1]\"
";
} else {
system("mkdir $fulldir");
system("chmod 0777 $fulldir");
//system("mv $slash[1] $todir");
print "Making directory $fulldir
";
}
}
}
$qst = ftp_quit ($status);
if (!$qst) { die ("Failed while Disconnecting from $host
"); }
} else {
print "
Web Site Copier