php操作ftp

WBOY
Release: 2016-06-23 13:56:30
Original
925 people have browsed it

上代码

//先创建一个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);				}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template