Location: PHPKode > scripts > VINDOZO: FTP-COPY ver.1.2 FREE > vindozo-ftp-copy-ver-1-2-free/ftp.php
<? $TimeHtml=time(); 
/* Vindozo FTP-Copy. 
 ver.1.2 FREE / 25.01.2008  (upon vindozo.com)
 Please, do not public this script in Internet!!!
*/

if(empty($_POST)) {?>
<html>
<head>
  <title>VINDOZO: FTP-COPY</title>

<script language='JavaScript'>
function procform()
{ var f = document.forms['cform'];

  var rexp = /^[a-z_\d\-\.]{8,64}$/;
  f.host_from.value = f.host_from.value.toLowerCase();
  if (!rexp.test(f.host_from.value))
  { alert(' No valid FTP-server FROM \n\n string:"a-z -_ 0-9" length:8-64 \n example:ftp.server.net');
    return false;
  }
  f.host_to.value = f.host_to.value.toLowerCase();
  if (!rexp.test(f.host_to.value))
  { alert('No valid FTP-server TO \n\n string:"a-z -_ 0-9" length:8-64 \n example:ftp.server.net');
    return false;
  }

  rexp = /^[a-z_\d\-]{2,32}$/;
  f.user_from.value = f.user_from.value.toLowerCase();
  if (!rexp.test(f.user_from.value))
  { alert('No valid login FROM \n\n string:"a-z -_ 0-9" length:2-32 \n example:user');
    return false;
  }
  f.user_to.value = f.user_to.value.toLowerCase();
  if (!rexp.test(f.user_to.value))
  { alert('No valid login TO \n\n string:"a-z -_ 0-9" length:2-32 \n example:user-1000');
    return false;
  }

  rexp = /^[a-zA-Z0-9]{2,32}$/;
  if (!rexp.test(f.pass_from.value))
  { alert('No valid password FROM \n\n string:"a-z A-Z 0-9" length:2-32 \n example:paSSword1000');
    return false;
  }
  if (!rexp.test(f.pass_to.value))
  { alert('No valid password TO \n\n string:"a-z A-Z 0-9" length:2-32 \n example:paSSword1000');
    return false;
  }

  var rexp = /^[a-z\A-Z\d\_\-\.\/]{2,256}$/;
  if (!rexp.test(f.dir_list_to.value)||(f.dir_list_to.value.substr(0,1)=='/')||(f.dir_list_to.value.substr(f.dir_list_to.value.length-1,1)=='/'))
  { alert('No valid directory TO \n\n string:"a-z A-Z 0-9 ._-/" length:2-256 \n not use symbol "/" is begin and end \n example:www/site.com/images');
    return false;
  }

  var rexp = /^[a-z\A-Z\d\_\-\.\/]{2,256}$/;
  if (!rexp.test(f.dir_list_from.value)||(f.dir_list_from.value.substr(0,1)=='/')||(f.dir_list_from.value.substr(f.dir_list_from.value.length-1,1)=='/'))
  { alert('No valid directory FROM \n\n string:"a-z A-Z 0-9 ._-/" length:2-256 \n not use symbol "/"  is begin and end \n example:www/site.com/images');
    return false;
  }

  return true;
}


function isfont(font){
f1=document.createElement("DIV");
f2=document.createElement("SPAN");
f1.appendChild(f2);
f1.style.visibility='hidden';
f1.style.fontFamily = "sans-serif"; f2.style.fontFamily = "sans-serif";
f2.style.fontSize = "72px"; f2.innerHTML = "mmmmmmmmmml";
document.body.appendChild(f1);
 var defaultWidth = f2.offsetWidth; var defaultHeight = f2.offsetHeight;
document.body.removeChild(f1);
document.body.appendChild(f1);
 var f = []; f[0] = f2.style.fontFamily = font; f[1] = f2.offsetWidth; f[2] = f2.offsetHeight;
document.body.removeChild(f1);
font = font.toLowerCase();
if (font == "arial" || font == "sans-serif") {
 f[3] = true;
} else {f[3] = (f[1] != defaultWidth || f[2] != defaultHeight);}
return f; 
}
webdings=false;

function webdingsico(a,b){
if(webdings) {document.write(a)} else {document.write(b)}
}

</script>
<style>
.table1{background-color:#6E7100;color:#FFFFFF;border-bottom:1px solid #474A03}
.table2{background-color:#DAEAF7;color:#000000;border-top:1px solid #9DA77B;border-bottom:1px solid #FFF4C2}
.table3{background-color:#F1B942;color:#000000;border-top:1px solid #E0BE76;border-bottom:1px solid #FFD165;padding:10px}
.table4{background-color:#A3271B;color:#F0A56E;border-top:2px solid #7D0D00}
.table5{background-color:#F6D271;color:#000000;border:3px solid #FFD66D;padding:10px;font-size:13px;}

.table6{border-right:3px solid #38607B;font-size:13px;}
.table7{border-left:3px solid #38607B;font-size:13px;}
#table6 td, #table7 td{padding-left:10px;padding-right:10px;}

.table8{font-family:"Trebuchet MS", "Franklin Gothic Book", Arial;font-size:13px;}

.logo{color:#FFFFFF;border:0px solid #FFF}
.logoico{color:#EABA28;font-family:Webdings;font-size:80px;}
.ico1{color:#A3271B;font-family:Webdings;font-size:30px;}
.ico2{color:#38607B;font-family:Webdings;font-size:30px;}
.ico3, .ico4{color:#A3271B;font-family:Webdings;font-size:15px;}

.logotitle1{color:#FFFFFF;font-family:"Felix Titling", Georgia, Times;font-size:30px;}

a, .logotitle2{color:#EABA28;font-family:"Trebuchet MS", "Franklin Gothic Book", Arial;font-size:13px;}
body{background-color:#FFFFFF;color:#000000;font-family:"Trebuchet MS", "Franklin Gothic Book", Arial;font-size:13px;}
a:hover, a:active, a:focus {color: #FACA38;}

a.download {color: #222;font-family:"Trebuchet MS", "Franklin Gothic Book", Arial;font-size:13px;}
a.download:hover {color: #444;}

.input1{background-color:#EEEEFF;border:1px solid #38607B;}
.input2{background-color:#FFFFFF;border:1px solid #18304B;}

button{font-family:"Trebuchet MS", "Franklin Gothic Book", Arial;font-size:13px;cursor:hand}

</style>
</head>

<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" id="scrn" name="scrn">
<script> webdings=isfont('Webdings')[3]; </script>

<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td height="50" class="table1" align="center">
<table width="600"  height="100" class="logo">
<tr><td width="150" class="logoico"><script>webdingsico("&#0251;","&#9632;")</script></td>
<td align="left" width="450"><span class="logotitle1">VINDOZO: FTP-COPY</span><br /><span class="logotitle2">connecting servers</span></td></tr></table>

</td></tr><tr><td height="100%" class="table2">
<br />
<form name="cform" action="ftp.php" method="post">
<table width="635" align=center><tr><td align=left>
<table width="300" align=center class="table6" id="table6">
  <tr><td colspan=2><span class="ico2"><script>webdingsico("&#0211;","&#9632;")</script></span> <b>Get directory FROM:</b></td></tr>
  <tr><td width=20%><nobr>FTP-Server:</nobr></td><td width=80%><input name="host_from" type="text" value="" style="width:100%" class="input1" onmouseover='this.className="input2"' onmouseout='this.className="input1"'></td></tr>
  <tr><td width=20%>Login:</td><td width=80%><input name="user_from" type="text" value="" style="width:100%" class="input1" onmouseover='this.className="input2"' onmouseout='this.className="input1"'></td></tr>
  <tr><td width=20%>Password:</td><td width=80%><input name="pass_from" type="text" value="" style="width:100%" class="input1" onmouseover='this.className="input2"' onmouseout='this.className="input1"'></td></tr>
  <tr><td width=20%>Directory:</td><td width=80%><input type="text" name="dir_list_from" value="" style="width:100%" class="input1" onmouseover='this.className="input2"' onmouseout='this.className="input1"'></td></tr>
</table>
</td><td align=center><span class="ico2"><script>webdingsico("&#056;","&#0187;")</script></span>
</td><td align=right>
<table width="300" align=center class="table7" id="table7">
  <tr><td colspan=2><span class="ico2"><script>webdingsico("&#0210;","&#9632;")</script></span> <b>And copy TO:<b></td></tr>
  <tr><td width=20%><nobr>FTP-Server:</nobr></td><td width=80%><input name="host_to" type="text" value="" style="width:100%" class="input1" onmouseover='this.className="input2"' onmouseout='this.className="input1"'></td></tr>
  <tr><td width=20%>Login:</td><td width=80%><input name="user_to" type="text" value="" style="width:100%" class="input1" onmouseover='this.className="input2"' onmouseout='this.className="input1"'></td></tr>
  <tr><td width=20%>Password:</td><td width=80%><input name="pass_to" type="text" value="" style="width:100%" class="input1" onmouseover='this.className="input2"' onmouseout='this.className="input1"'></td></tr>
  <tr><td width=20%>Directory:</td><td width=80%><input type="text" name="dir_list_to" value="" style="width:100%" class="input1" onmouseover='this.className="input2"' onmouseout='this.className="input1"'></td></tr>
</table>
</table>
<br />
<center><button onclick="if(procform())document.forms['cform'].submit();" ><span class="ico3"><script>webdingsico("&#056;","&#0187;")</script></span> TRANSFER</button>
<br /><br />

</td></tr><tr><td height="100" class="table3" align="center">

<table width=620><tr><td>

<table width="300" height="100%" align="center" class="table5">
<tr><td width="5%" valign="top" class="ico1" ><script>webdingsico("&#0235;","&#9632;")</script></td>
<td>
Copy directory include subdirectories and files, and set correct CMOD. All directories should have CMOD a minimum 500, all files a minimum 400. A directory start of this script 777 CMOD, for creating tmp files.
</td></tr></table>

</td><td>


<table width="300" height="100%" align=center class="table8">
<tr><td width=5% valign="top"><b>Future:</b></td>
<td><span class="ico4"><script>webdingsico("&#097;","&#0149;")</script></span> Module MYSQL-Copy<br/>
<span class="ico4"><script>webdingsico("&#097;","&#0149;")</script></span> Module EMAIL-Copy
<br/><br/><span class="ico4"><script>webdingsico("&#205;","&#9632;")</script></span> Download <b><a href="ftp.zip" class="download">ftp.zip</a></b>
</td></tr>
</table>

</td></tr></table>

</td></tr><tr><td height="30" class="table4 logotitle2" align="center">
&copy; All rights are reserved | <a href="http://vindozo.com" >vindozo.com</a> | ver.1.2 FREE / 27.01.2008
</form>
</td></tr></table>
</body>

</html>
<? }else{
  set_time_limit(3000);
  $size_a=0; $size_b=0;
  $count_d=0; $count_f=0;
  $host_from = $_POST["host_from"];

  $tmp=0;
  foreach ($_POST as $check) {
	if ($check!=htmlspecialchars($check)) {exit("Protection: POST attack is revealed!");
 	} else {$tmp+=crc32($check);};
  };
  $freport=fopen("rep".$tmp.".htm","w");
  if(!$freport){exit("A directory start of this script 777 CMOD, for creating tmp files!");}

  echoout("<html><head><title>VINDOZO: FTP-COPY</title></head><body style='font-family:Arial;font-size:13px;'>");

  $ip_from = @gethostbyname($host_from);
  if($ip_from == $host_from) exit("Server <b>$host_from</b> NOT found.");
 
  else
  { echoout("Connect from <b>$host_from</b> ($ip_from)..."); flush();
    $ftp_handle_from = @ftp_connect($ip_from);
    if (!$ftp_handle_from) exit(" Error connect!");
    else echoout(" Connect ok.<br>");
    echoout("Login <b>$host_from</b>..."); flush();
    $user_from = $_POST["user_from"];
    $pass_from = $_POST["pass_from"];
    if(!@ftp_login($ftp_handle_from,$user_from,$pass_from)) { echoout(" Login or password not valid <br>");
                                                              echoout("Exit <b>$host_from</b>..."); flush();
                                                              @ftp_quit($ftp_handle_from);
                                                              exit(" Connection closed."); flush();
                                                            }
    else echoout(" login <b>$user_from:$pass_from</b> ok!<br>"); flush();
  }

  $host_to = $_POST["host_to"];
  $ip_to = @gethostbyname($host_to);
  if($ip_to == $host_to) { echoout("Server <b>$host_to</b> NOT found.<br>");
                           echoout("Exit <b>$host_from</b>..."); flush();
                           @ftp_quit($ftp_handle_from);
                           exit(" Connection closed."); flush();
                         }
  else
  { echoout("Connect from <b>$host_to</b> ($ip_to)..."); flush();
    $ftp_handle_to = @ftp_connect($ip_to);
    if (!$ftp_handle_to) { echoout(" Error connection!<br>");
                           echoout("Exit <b>$host_from</b>..."); flush();
                           @ftp_quit($ftp_handle_from);
                           exit(" Connection closed."); flush();
                         }
    else echoout(" Connection ok.<br>");
    echoout("Login <b>$host_to</b>..."); flush();
    $user_to = $_POST["user_to"];
    $pass_to = $_POST["pass_to"];
    if(!@ftp_login($ftp_handle_to,$user_to,$pass_to)) { echoout(" Login or password not valid<br>");
                                                        echoout("Exit <b>$host_to</b>..."); flush();
                                                        @ftp_quit($ftp_handle_to);
                                                        echoout(" Connection closed.<br>"); flush();
                                                        echoout("Exit <b>$host_from</b>..."); flush();
                                                        @ftp_quit($ftp_handle_from);
                                                        exit(" Connection closed."); flush();
                                                      }
    else echoout(" login <b>$user_to:$pass_to</b> ok!<br>"); flush();
  }

  $dir_list_from = str_replace("\r\n","\n",$_POST["dir_list_from"]);
  $dir_list_to = str_replace("\r\n","\n",$_POST["dir_list_to"]);

  $dir_list_from = explode("\n",$dir_list_from);
  $dir_list_to = explode("\n",$dir_list_to);

  while(($dir_list_from[0] == "") && (sizeof($dir_list_from) > 1)) array_shift($dir_list_from);
  while(($dir_list_to[0] == "") && (sizeof($dir_list_to) > 1)) array_shift($dir_list_to);

  while($key = array_search("",$dir_list_from)) { unset($dir_list_from[$key]);
                                                  $dir_list_from = array_values($dir_list_from);
                                                }
  while($key = array_search("",$dir_list_to)) { unset($dir_list_to[$key]);
                                                $dir_list_to = array_values($dir_list_to);
                                              }
  if($dir_list_from[0] == "")
    echoout("<b>Path FROM is empty!</b><br>");
  elseif($dir_list_to[0] == "")
    echoout("<b>Path TO is empty!</b><br>");
  elseif(($dir_co = sizeof($dir_list_from)) != sizeof($dir_list_to))
    echoout("<b>?!</b><br>");
  else
  { echoout("<font color=gray >");
    for($i = 0; $i < $dir_co; $i++)
    { $dir_list_from[$i] = str_replace("\\","/",$dir_list_from[$i]);
      $dir_list_from[$i] = str_replace("//","/",$dir_list_from[$i]);
      if($dir_list_from[$i][0] == "/") $dir_list_from[$i] = substr($dir_list_from[$i],1);
      if($pos = strrpos($dir_list_from[$i],"/"))
      { $up_dir_from = substr($dir_list_from[$i],0,$pos);
        $copy_dir_from = substr($dir_list_from[$i],$pos+1);
      }
      else
      { $up_dir_from = "";
        $copy_dir_from = $dir_list_from[$i];
      }
      if($up_dir_from)
      { echoout("Go from ".$up_dir_from."..."); flush();
        if(@ftp_chdir($ftp_handle_from,$up_dir_from))
          echoout(" ok<br>");
        else echoout("<b> Error!</b><br>");
      }
      $dir_list = @ftp_rawlist($ftp_handle_from,".");
      $perm = "";
      foreach($dir_list as $file)
        if($file[0] == "d" && substr($file,strrpos($file," ")+1) == $copy_dir_from)
        { $perm = substr($file,1,9);
          break;
        }
      if(!$perm) { echoout("Directory <b>".$dir_list_from[$i]."</b> not found!<br>"); flush(); }
      else
      { echoout("Copy directory <b>".$dir_list_from[$i]."</b> to <b>".$dir_list_to[$i]."</b>...<br>"); flush();
        copy_dir($ftp_handle_from,$ftp_handle_to,$copy_dir_from,$dir_list_to[$i],$perm,1);
      }
      for($j = 0; $j <= substr_count($up_dir_from,"/"); $j++)
        @ftp_cdup($ftp_handle_from);
    }
    echoout("</font>");
  }

  echoout("Exit <b>$host_to</b>..."); flush();
  @ftp_quit($ftp_handle_to);
  echoout(" Connection closed.<br>"); flush();

  echoout("Exit <b>$host_from</b>..."); flush();
  @ftp_quit($ftp_handle_from);
  echoout(" Connection closed.<br>"); flush();
  echoout(" <br><br> Stat:<br> ");
  echoout(" Copied <b>".$size_a."</b> bytes <br>");
  echoout(" Copied <b>".$count_d."</b> directories<br>");
  echoout(" Copied <b>".$count_f."</b> files<br>");
  echoout(" Time <b>".(time()-$TimeHtml)."</b> sec <br>");
  echoout(" Report file: <b><a href='rep".$tmp.".htm'>rep".$tmp.".htm</a></b>");
  echoout("</body></html>");
  @fclose($freport);

}

//-------------------------------

  function getchmod($perm)
  {
    $chmod = 0;
    if($perm[0] == "r") $chmod = $chmod+0400;
    if($perm[1] == "w") $chmod = $chmod+0200;
    if($perm[2] == "x") $chmod = $chmod+0100;
    if($perm[3] == "r") $chmod = $chmod+0040;
    if($perm[4] == "w") $chmod = $chmod+0020;
    if($perm[5] == "x") $chmod = $chmod+0010;
    if($perm[6] == "r") $chmod = $chmod+0004;
    if($perm[7] == "w") $chmod = $chmod+0002;
    if($perm[8] == "x") $chmod = $chmod+0001;
    return $chmod;
  }

  function f_size()
  { global $size_a, $size_b, $tmp;
    $size_b=filesize("ftp".$tmp.".tmp");
    $size_a=$size_a+$size_b;
    return true;
  }


  function copy_dir($ftp_from,$ftp_to,$dir_from,$dir_to,$perm,$lev)
  { global $size_a, $size_b, $count_d, $count_f, $tmp;
    echoout( str_repeat("&#9474;",$lev-1)."&#9500;"."&#9472;Create <b>$dir_to</b>..."); flush();
    $no_errors = true;
    $dir_list_to = explode("/",$dir_to);
    foreach($dir_list_to as $dir)
    { $dir_exist = false;
      $dir_list = ftp_rawlist($ftp_to,".");
      foreach($dir_list as $file)
        if($file[0] == "d" && substr($file,strrpos($file," ")+1) == $dir)
        { $dir_exist = true;
          break;
        }
      if($dir_exist) $no_errors = ($no_errors &&
                                   ftp_site($ftp_to,"chmod 0777 $dir") &&
                                   ftp_chdir($ftp_to,$dir));
      else $no_errors = ($no_errors &&
                         is_string(ftp_mkdir($ftp_to,$dir)) &&
                         ftp_site($ftp_to,"chmod 0777 $dir") &&
                         ftp_chdir($ftp_to,$dir));
    }
    if($no_errors) echoout(" ok<br>");
    else echoout("<b> Error!</b><br>");
    flush();

    if(ftp_chdir($ftp_from,$dir_from))
      echoout( str_repeat("&#9474;",$lev-1)."&#9500;"."&#9516;Go in <b>$dir_to</b><br>");
    else echoout( str_repeat("&#9474;",$lev-1)."&#9472;<b>Error:</b> Error step to <b>$dir_to</b><br>");
    flush(); 
    $count_d++;

    echoout( str_repeat("&#9474;",$lev)."&#9500;"."&#9472;Read <b>$dir_from</b><br>");
    flush();

    $dir_list = ftp_rawlist($ftp_from,".");

    foreach($dir_list as $file)
      if($file[0] == "-")
      { $fperm = substr($file,1,9);
        $fname = substr($file,strrpos($file," ")+1);
        $chmod = getchmod($fperm);

        echoout( str_repeat("&#9474;",$lev)."&#9500;"."&#9472;Copy file <b>$fname</b>..."); flush();
        if((@ftp_get($ftp_from,"ftp".$tmp.".tmp",$fname,FTP_BINARY) ||
            @ftp_get($ftp_from,"ftp".$tmp.".tmp",$fname,FTP_ASCII)) &&
           (@ftp_put($ftp_to,$fname,"ftp".$tmp.".tmp",FTP_BINARY) ||
            @ftp_put($ftp_to,$fname,"ftp".$tmp.".tmp",FTP_ASCII)) &&
           ftp_site($ftp_to,"chmod ".base_convert($chmod,10,8)." $fname") &&
           f_size()&&unlink("ftp".$tmp.".tmp")) {echoout(" (".$size_b." bytes) ok<br>"); $count_f++;}
        else echoout("<b> Error!</b><br>");
      }

    foreach($dir_list as $file)
      if($file[0] == "d")
      { set_time_limit(300);
        $fperm = substr($file,1,9);
        $fname = substr($file,strrpos($file," ")+1);

        if($fname <> "." && $fname <> "..")
        { echoout( str_repeat("&#9474;",$lev)."&#9500;"."&#9472;Copy directory <b>$fname</b>...<br>"); flush();
          copy_dir($ftp_from,$ftp_to,$fname,$fname,$fperm,$lev+1);
        }
      }

    echoout(str_repeat("&#9474;",$lev)."&#9500;"."&#9472;Go <b>up</b>..."); flush();
    for($j = 0; $j <= substr_count($dir_to,"/"); $j++)
      ftp_cdup($ftp_to);
    if(ftp_cdup($ftp_from)) echoout(" ok<br>");
    else echoout("<b> Error!</b><br>");
    flush();

    $chmod = getchmod($perm);
    if(ftp_site($ftp_to,"chmod ".base_convert($chmod,10,8)." ".$dir_to))
      echoout( str_repeat("&#9474;",$lev)."&#9492;On <b>$dir_to</b> set chmod(0".base_convert($chmod,10,8).")<br>");
    else echoout( str_repeat("&#9474;",$lev)."&#9500;"."&#9472;<b>Error:</b> Error set chmod(0".base_convert($chmod,10,8).") on <b>$dir_to</b><br>");
    flush();
  }

  function echoout($a){
   global $freport;
   echo $a;
   @fputs($freport,$a." \r\n");
  }


?>
Return current item: VINDOZO: FTP-COPY ver.1.2 FREE