欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php操作ftp

程序员文章站 2024-01-05 18:53:52
...
上代码
//先创建一个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);				}
相关标签: php ftp 操作

上一篇:

下一篇: