php操作ftp

上代码
//先创建一个xml文件
$file=fopen($result_a[0]["code"].".xml","w");
fwrite($file, $str);
fclose($file);
			
//链接ftp
$ftp=ftp_connect("1.1.1.1") or die("连接远程服务器失败!");
ftp_login($ftp,"user","pwd") or die ("帐号或密码错误!");
			
//判断ftp上文件是否存在,如果不存在则返回-1,存在则返回文件的大小
$file_exist=ftp_size($ftp,"/cur/".$result_a[0]["code"].".xml");
			
if ($file_exist=="-1"){
	//上传文件到ftp上
	$uplodexml=ftp_put($ftp,"/cur/".$result_a[0]["code"].".xml",$result_a[0]["code"].".xml",FTP_ASCII);
}else{
	//先重命名老的文件
	$new_xml=$result_a[0]["code"]."_".date("Ymd")."xml";
	/*$newname=ftp_rename($ftp,"/cur/".$result_a[0]["code"].".xml","/cur/".$new_xml);*/
				
	//将老文件下载到本地,再上传到服务器的备目录中
	$oldfile=ftp_get($ftp,$new_xml,"/cur/".$result_a[0]["code"].".xml",FTP_ASCII);
	$uplodeoldxml=ftp_put($ftp,"/bak/".$new_xml,$new_xml,FTP_ASCII);
				
	if (!$uplodeoldxml){
		echo "error";
		exit;
	}
				
	//上传新的ftp文件 ,会将同名的文件覆盖掉
	$uplodexml=ftp_put($ftp,"/cur/".$result_a[0]["code"].".xml",$result_a[0]["code"].".xml",FTP_ASCII);
				
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值