|
php实现的使用ftp自动更新上传文件的代码,有需要的朋友,可以参考下。
完整代码。
I-Shop购物系统
部分功能简介:商品收藏夹功能热门商品最新商品分级价格功能自选风格打印结算页面内部短信箱商品评论增加上一商品,下一商品功能增强商家提示功能友情链接用户在线统计用户来访统计用户来访信息用户积分功能广告设置用户组分类邮件系统后台实现更新用户数据系统图片设置模板管理CSS风格管理申诉内容过滤功能用户注册过滤特征字符IP库管理及来访限制及管理压缩,恢复,备份数据库功能上传文件管理商品类别管理商品添加/修改/
下载
Mirror update
';
exit;
}
echo "Connected to $host. ";
@ $result=ftp_login($conn,$user,$password);
if(!$result)
{
echo "Error: 用户 $user 登录失败。 ";
ftp_quit($conn);
exit;
}
echo "login as $user ";
//check file times to see if an update is required
echo 'Checking file time....';
if(file_exists($localfile))
{
$localtime=filetime($localfile);
echo 'Local file last updated';
echo date('G:i j-M-Y',$localtime);
echo ' ';
}
else
$localtime=0;
$remotetime=ftp_mdtm($conn,$remotefile);// 获取远程文件的修改时间函数
if (!($remotetime>=0))
{
echo 'Can/'t access remote file time. ';
$remotetime=$localtime+1; //make sure of an update
}
else
{
echo 'Remote file last updated';
echo date('G:i j-M-Y',$remotetime);
echo ' ';
}
if(!($remotetime>$localtime))
{
echo 'Local copy is up to date. ';
exit;
}
//download file
echo 'Getting file from server.... ';
$fp=fopen($localfile,'w');
if(!$success=ftp_fget($conn,$fp,$remotefile));
{
echo 'Error:Could not download file';
ftp_quit($conn);
exit;
}
fclose($fp);
echo "File download successfully";
//close connection to host
ftp_quit($conn);
//fget()函数的用法:
//ftp_get($conn,$localfile,$remotefile);
?>
|