<?
/*******************************************************************************/
/* 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 ("<center><h1>FTP CONNECTION FAILED TO $host</h1></center>"); }
$login = ftp_login ($status,$username,$pswd);
if (!$login) { die ("<center><h2>Username or Password not accepted on host $host</h2></center>"); }
$dirlist = ftp_nlist ($status,$dir);
if (!$dirlist) { die ("<center><h3>Cannot read directory $dir on host $host</h3></center>"); }
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]<br>"; }
if ($todir != "") {
system("mv $slash[1] $todir");
}
print "Copying binary file $slash[1] from $host$eachfile<br>";
}
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]<br>"; }
if ($todir != "") {
system("mv $slash[1] $todir");
}
print "Copying document $slash[1] from $host$eachfile<br>";
}
} else {
if (in_array($slash[1],$frontpage)) {
print "Passing Frontpage ekstention directory \"$slash[1]\"<br>";
} else {
system("mkdir $fulldir");
system("chmod 0777 $fulldir");
//system("mv $slash[1] $todir");
print "Making directory $fulldir<br>";
}
}
}
$qst = ftp_quit ($status);
if (!$qst) { die ("<center><h1>Failed while Disconnecting from $host</h1></center>"); }
} else {
print "
<html>
<head>
<meta http-equiv=\"Content-Language\" content=\"en-us\">
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">
<meta name=\"Register_Your_Copy_to\" content=\"mailto:[email protected]\">
<meta name=\"Web_Site_Copier\" content=\"Version 1.0 Beta\">
<title>Web Site Copier</title>
</head>
<body>
<form method=\"POST\" action=\"ftpcopy.php\">
<h1 align=\"center\"><font color=\"#000080\">Web Site Copier<br>
</font></h1>
<table border=\"0\" width=\"100%\" cellspacing=\"0\">
<tr>
<td width=\"28%\"></td>
<td width=\"46%\"><font face=\"Verdana\"><b>Source Host :</b></font></td>
<td width=\"26%\"></td>
</tr>
<tr>
<td width=\"28%\"></td>
<td width=\"46%\">
<table border=\"0\" width=\"100%\">
<tr>
<td width=\"44%\"><font face=\"Verdana\">Host</font></td>
<td width=\"5%\" align=\"center\">:</td>
<td width=\"51%\"><input type=\"text\" name=\"host\" size=\"28\" value=\"ftp://\"></td>
</tr>
<tr>
<td width=\"44%\"><font face=\"Verdana\">Username</font></td>
<td width=\"5%\" align=\"center\">:</td>
<td width=\"51%\"><input type=\"text\" name=\"username\" size=\"17\"></td>
</tr>
<tr>
<td width=\"44%\"><font face=\"Verdana\">Password</font></td>
<td width=\"5%\" align=\"center\">:</td>
<td width=\"51%\"><input type=\"password\" name=\"pswd\" size=\"21\"></td>
</tr>
<tr>
<td width=\"44%\"><font face=\"Verdana\">Directory</font></td>
<td width=\"5%\" align=\"center\">:</td>
<td width=\"51%\"><input name=\"dir\" size=\"21\" value=\"/web\"></td>
</tr>
<tr>
<td width=\"44%\"><font face=\"Verdana\">To Directory</font></td>
<td width=\"5%\" align=\"center\">:</td>
<td width=\"51%\"><input name=\"todir\" size=\"21\"></td>
</tr>
<tr>
<td width=\"44%\"><br>
</td>
<td width=\"5%\" align=\"center\"></td>
<td width=\"51%\"></td>
</tr>
</table>
</td>
<td width=\"26%\"></td>
</tr>
</table>
<table border=\"0\" width=\"100%\" cellspacing=\"0\">
<tr>
<td width=\"28%\"><br>
</td>
<td width=\"46%\"></td>
<td width=\"26%\"></td>
</tr>
</table>
<p align=\"center\"><input type=\"submit\" value=\" OK Let's copy \" name=\"Button\"></p>
<input type=\"hidden\" name=\"action\" value=\"copy\">
</form>
<p align=\"center\"><br>
<br>
<b>Note :</b> If ftp connection failed, try using <a href=\"ftp://ftp.yourdomain.com\">ftp.yourdomain.com</a>
or <a href=\"http://www.yourdomain.com\">www.yourdomain.com</a> <br>
eliminate the "<a href=\"ftp://\">ftp:// </a>" protocol<br>
<br>
</p>
</body>
</html>";
}
?>