首页  >  文章  >  后端开发  >  php操作ftp

php操作ftp

WBOY
WBOY原创
2016-06-23 13:56:30889浏览

上代码

//先创建一个xml文件$file=fopen($result_a[0]["code"].".xml","w");fwrite($file, $str);fclose($file);			//链接ftp$ftp=ftp_connect("21.254.4.15") or die("连接远程服务器失败!");ftp_login($ftp,"swywb","swywbonly") 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);				}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn