<?php

ini_set('display_errors',1);
error_reporting(E_ALL);
define('ROOT', dirname(__FILE__));
$token = '123321';
$host = $_REQUEST['host'];
$dbg = $_REQUEST['dbg'];
$ftuuser = $_REQUEST['ftuuser'];
$ftppwd = $_REQUEST['ftppwd'];

if ($dbg > 0)
{
    echo '<pre>';
    print_r($_REQUEST);
    exit;
}

if (!checkToken($token)) {
    render(-3, '', 'token is wrong!');
}

unset($_REQUEST['dbg']);

pushURI($host, $ftuuser, $ftppwd);

function checkToken($token)
{
    if (trim($_REQUEST['token']) == $token) {
        unset($_REQUEST['token']);
        return 1;
    }
    return 0;
}


//提交
function pushURI($url,$ftuuser,$ftppwd)
{

    $curlobj = curl_init(); //初始化
    //传入ftp的目标文件，如'ftp://192.168.3.1/test/1.jpg'
    curl_setopt($curlobj, CURLOPT_URL, $url);
    curl_setopt($curlobj, CURLOPT_HEADER, 0); //不输出header
    curl_setopt($curlobj, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curlobj, CURLOPT_TIMEOUT, 20); //超时时间
    //通过这个函数设置ftp的用户名和密码,没设置就不需要!
    curl_setopt($curlobj, CURLOPT_USERPWD, $ftuuser . ':' . $ftppwd);
    //date('YmdH12',strtotime ("-4 hours")).'.xml';

    $rtn['xml'] = curl_exec($curlobj);
    $rtn['httpcode'] = curl_getinfo($curlobj);
print_r($rtn);
    if (curl_errno($curlobj))
    {
        return false;
    }

    curl_close($curlobj);

    return $rtn;
}
