论坛首页 编程语言技术论坛

指定SVN版本FTP上传更新文件(PHP版)

浏览 3146 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-07-24  
PHP
菜鸟写的php小脚本,apache执行需指定用户权限.
将指定svn版本号(GET参数s)更新的文件上传到FTP上

<?php
$ftpserver = 'www.sitename.com';//ftp server
$ftpuser = 'test';//ftp user name
$ftppassword = 'test';//ftp user password
$svnrepository = "d:\web";//svn repository directory
$svnbinpath = "";//svn bin file directory


if($v1 = $_GET['s'])
{//版本号
	$r = array();//执行外面svn命令返回的信息数组
	$f = array();//匹配文件
	$fa = array();//所有需上传的匹配文件
	if($v2 = $_GET['e'])
	{//至版本号(从起始版本号至版本号所有文件)
		exec($svnbinpath." svn log $svnrepository -r {$v1}:{$v2} -q -v",$r);
	}
	else
	{//单版本号
		exec($svnbinpath." svn log $svnrepository -r {$v1} -q -v",$r);
	}
	
	foreach($r as $value)
	{
		if(preg_match("/^[ ]*[AM]{1} (\/.+)$/i",$value,$f))
		{//符合文件更新规则的文件名放入上传数组
			$fa[] = $f[1];
		}
	}
	echo "revision: $v1 ".(($v2)?" - $v2":'')." need upload files:\n<br>";
	foreach($fa as $value)
	{
		echo $svnrepository.$value."\n<br>";
	}

	if($fa)
	{
		$conn_id = ftp_connect($ftpserver);
		$login_result = ftp_login($conn_id,$ftpuser,$ftppassword);
		if ((!$conn_id) || (!$login_result)) 
		{
				echo "FTP connection has failed! :(\n<br>";
				exit();
		}
		else
		{
				echo "\n<br>Connected to $ftpserver ftp\n<br>";
		}

		foreach($fa as $value)
		{
			$upload = ftp_put($conn_id, str_replace('\\','/',$value), $svnrepository.$value, FTP_BINARY);
			if($upload)
			{
				echo "upload $value succeed :)\n<br>";
			}
			else
			{
				echo "upload $value failed :(\n<br>";
			}
		}
		echo "upload completed";
		ftp_close($conn_id);
	}
}
else
{//无参数提示
	echo '请输入版本号参数s,如需连续多个版本则加上参数e';
}
?>
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics