php获取svn文件,然后ftp上传服务器代码

配置文件

<?php 

//setup commandline 
$svn_cmd1 = 'svn.exe update '; 
$svn_cmd2 = ' --username xxx --password xxx '; 

$ftp_ip = '#########'; 
$ftp_user = '#########'; 
$ftp_pass = '#########'; 
?> 

 
php获取svn文件,然后ftp上传服务器代码

<?php 
require_once("config.php"); 

// CONFIG dir 
$CONFIG_PG = 'E:\phpupdate\xxx'; 

// svn上传文件列表 
$svnlist = array(); 
$svnlist = updatesvn($svn_cmd1,$CONFIG_PG,$svn_cmd2); 

/* 
$svnlist[0]= 'A E:\XXXX\Lib\Action\XXXAction.class.php'; 
$svnlist[1]= 'U E:\XXXXX\Action\XXXAction.class.php'; 
$svnlist[2]= 'At revision 5625.'; 
*/ 

$remoteArr = $svnlist; //ftp上传文件列表 
$localArr = $svnlist; //本地文件列表 

//输出svn信息 
svnMessage(&$remoteArr,&$localArr,$CONFIG_PG); 

//上传 
ftp_upload($ftp_ip,$ftp_user,$ftp_pass,$localArr,$remoteArr); 

/** 
* 上传svn更新 
*/ 
function updatesvn($svn_cmd1,$CONFIG_PG,$svn_cmd2) 
{ 
//execute svn update command 
$cmd = $svn_cmd1 . $CONFIG_PG . $svn_cmd2; 
//echo 'Debug:'.$cmd. "<br />\r\n"; 

$ar = array(); 
$status = 0; 
exec($cmd, $ar, $status); 

if ( count($ar) <= 1 ) 
{ 
echo $ar[0]; 
echo '<br>no upload file!'; 
exit; 
} 

//print_r($ar); 

echo  "Status: " .$status . "<br />\r\n"; 
return $ar; 
} 

/** 
* 输出调试信息 
*/ 
function svnMessage($remoteArr,$localArr,$CONFIG_PG) 
{ 
/* 
* local dir 
*/ 
for($ctr = 0;$ctr < count($localArr)-1; $ctr++) 
{ 
//$localArr[$ctr] = str_replace ($CONFIG_FLG,'',$localArr[$ctr]); 
$istr = stripos($localArr[$ctr], $CONFIG_PG); 
$localArr[$ctr] = substr($localArr[$ctr],$istr); 
$localArr[$ctr] = str_replace ('\\','/',$localArr[$ctr]); 
} 
echo "本地路径:<br />\r\n"; 
for($ctr = 0;$ctr < count($localArr)-1; $ctr++) 
{ 
echo $localArr[$ctr]; 
echo "<br />\r\n"; 
} 

/* 
* remote dir 
*/ 
for($i = 0;$i < count($remoteArr)-1; $i++) 
{ 
//$remoteArr[$i] = str_replace ($CONFIG_PG,'',$remoteArr[$i]); 
$imstr = stripos($remoteArr[$i], $CONFIG_PG); 
$remoteArr[$i] = substr($remoteArr[$i],$imstr+strlen($CONFIG_PG)); 
$remoteArr[$i] = str_replace ('\\','/',$remoteArr[$i]); 
} 
echo "<br />\r\n上传路径:<br />\r\n"; 
for($i = 0;$i < count($remoteArr)-1; $i++) 
{ 
echo $remoteArr[$i]; 
echo "<br />\r\n"; 
} 
} 

/** 
* ftp上传脚本 
*/ 
function ftp_upload($ftp_ip,$ftp_user,$ftp_pass,$localPathArr,$remotePathArr) 
{ 
$conn = ftp_connect($ftp_ip) or die("Could not connect"); 
ftp_login($conn,$ftp_user,$ftp_pass); 

if ( count($localPathArr) == count($remotePathArr) ) 
{ 
for($i = 0;$i < count($localPathArr)-1; $i++) 
{ 
// 开始 
$fp = fopen($localPathArr[$i], 'r'); 
$ret = ftp_nb_fput($conn, $remotePathArr[$i], $fp, FTP_BINARY); 
while ($ret == FTP_MOREDATA) 
{ 
   // 加入其它要执行的代码 
   echo "...."; 
   // 继续传送... 
   $ret = ftp_nb_continue ($conn); 
} 
if ($ret != FTP_FINISHED) 
{ 
   echo "上传文件中发生错误..."; 
   exit(1); 
} 
} 
echo ".............................."; 
echo "<br />\r\n OK! <br />\r\n"; 
} 
else 
{ 
echo "svn check error!<br />\r\n"; 
} 

ftp_close($conn); 
} 




?>

 

 

你可能感兴趣的:(PHP,SVN,脚本,FP)