<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
	//同步ftp上传更新的英文站文件到，其他语种，主要是 变化的程序，新增， 修改上传: 文件、文件夹时间大于 数据库上次上传时间
	session_start();
	include("inc/ftp.php");
	ini_set('date.timezone','Asia/Shanghai');
	$config=array('ftp_ip'=>"slatestones.cn",
	'ftp_port'=>"21",
	'ftp_username'=>"slatestonesftp@slatestones.cn",
	'ftp_password'=>"T2kll&-lBm]N",
	'ftp_pasv'=>"");
	$ftp = new FtpFile($config);
	
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/ls_inccode.php');
	
	require_once('inc/check.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	
	$ls=$_GET['ls'];
	 
	$filearr="12.php.bak";
	$timestr=round((time()-1554627274)/20);
	//echo "/train2/old/".$filearr."---"."/train2/old/mov/".$filearr.$timestr;exit;
/*	$ls_msg.=$ftp->move_file("/train2/old/".$filearr, "/train2/old/mov/aa/ccc/".$filearr.$timestr)."<br/>";
	echo $ls_msg; exit;*/

	$select_sql2="select * from ls_ftplog where ip='".$config['ftp_ip']."' order  by date DESC ";
	//echo $select_sql2;
	$select_query2=$opendb->query($select_sql2);
	$select_rows2=mysql_fetch_assoc($select_query2); //总数
	$lasttime=strtotime($select_rows2['date']); //上次更新时间
	echo $lasttime."<br/>"; 
	//echo  filemtime("../Templates1")."<br/>"; 

	$scrDir="..";
	$nocopyfolder=explode(",","sitemap,m,update,certificate,download,blog,management,newspage,workshop,packing,certificate,history");
	$changecopyfolder=explode(",","Templates,Templates1,bootstrap,css,images,ls_admin,generalpics,jq22css,jq22js,js,motif,revolvingpics"); //增量
	$increasecopyfolder=array();   // 变化的，增量
	$skipfile=array("conn_var.php"); // 是这些的跳过 
	$ls_admininc=explode(",","inc,css,widget,kindeditor-4.1.10\attached,images,img,js"); //增量; 

	 xftpincrease($scrDir, $ftp,$nocopyfolder, "/train2/old",$skipfile,$increasecopyfolder,$changecopyfolder,$ls_admininc);


 	echo "<br/><br/>".$ls_msg;



$ftp->close();
 


/* 目录树遍历,ftp文件
   
//参数说明：   
// $source:源目录名   
// $destination:目的目录名   
// $child:复制时，是不是包含的子目录
// $nocopyfolder 无需复制的文件、目录（/folder）放到数组里
// $skipfile 无需复制的文件、目录包含就跳过
// $increasecopyfolder  目录里新增的拷贝
// $changecopyfolder 目录里变化的拷贝
 */
function xftpincrease($source, $ftp,$nocopyfolder=array(), $destination,$skipfile,$increasecopyfolder,$changecopyfolder,$ls_admininc)
{   
	global $lasttime;
	 
	//$filearr="12.php.bak";
	//$ls_msg.=$ftp->uploadFile($filearr)."<br/>";
	 
	
	if(!is_dir($source)){   
	echo("Error:the $source is not a direction!<br/>");   
	return 0;   
	}   
	 include("inc/constant.php");
	// echo $transFlags;
	$handle=dir($source);   
	while($entry=$handle->read()) {   
		if(($entry!=".")&&($entry!="..")){   
			  if(is_dir($source."/".$entry)) {    //目录 
				  if(1) { //跳过不考的  
					  if(!in_array( $entry,$nocopyfolder ))  { //上级不是ls_admin ，上级是ls_admin，且本级在$ls_admininc $destination."/".str_replace("../","",$source)."/".$entry
					   //echo "==1==".$destination."--/".$entry."<br/>";
						//if($ftp->dir_mkdirs($destination."/".$entry)) $ls_msg.="create ".$destination."/".$entry. " ok <br/>"; ; //建目录
						// echo "local $entry : ".filemtime($source."/".$entry);
						if(  ($source=="ls_admin" && strin($entry,$ls_admininc)) || $source!="ls_admin"  )
						{xftpincrease($source."/".$entry, $ftp ,$nocopyfolder,$destination."/".$entry,$skipfile,$increasecopyfolder,$changecopyfolder,$ls_admininc);
						// echo "local $entry : ".filemtime($source."/".$entry);
						}
					  }
				  }
			  }   
			  else
			  {    
			   	   $thisfold=substr($source,(strrpos($source,"/")+1));
			  	  // echo $source."/-".$entry."---". $thisfold."---".$destination."/-".$entry."  <br/>";
			  		//文件//检查复制文件 
				  if( in_array($thisfold,$changecopyfolder ) && !strin($entry,$skipfile ) ){
					  		//if($ftp->dir_mkdirs($destination)) $ls_msg.="create ".$destination. " ok <br/>"; ; //建目录
					  		if( filemtime($source."/".$entry) > $lasttime )  {  //不存在目标文件，复制
							// echo $source."/".$entry."=2=". $destination."/".$entry."<br/>";
								 if( $ftp->upafile($source."/".$entry,$destination."/".$entry ))
								  	{$ls_msg.="up1 ".$source."/".$entry." -- ". $destination."/".$entry." ok <br/>";
									// echo "local2 $entry : ".filemtime($source."/".$entry);
									}
							} 
					  }
					  else { //增量复制
						  if( strin($source,$increasecopyfolder )   ){ 
							  if( filemtime($source."/".$entry) > $lasttime )  { //判断文件存在
								  if($ftp->upafile($source."/".$entry,$destination."/")) 
								  	{$ls_msg.="up2 ".$source."/".$entry." -- ".  $destination."/".$entry." ok <br/>";
									 //echo "local3 $entry : ".filemtime($source."/".$entry);
									}
							  }
						  }
					  }
				  
			  }   
		}   
	}   
	echo "".$ls_msg;
	return 1;   
}  
 
?>