Php 尝试使用Curl连接到FTP时收到“内部服务器错误”

Php 尝试使用Curl连接到FTP时收到“内部服务器错误”,php,codeigniter,curl,internal-server-error,Php,Codeigniter,Curl,Internal Server Error,好吧,这有点让我发疯。。。我在尝试使用Curl连接到外部FTP连接时一直收到一个内部服务器错误。我可以正常访问FTP,但不能通过Curl访问 我使用CodeIgniter作为包装器,但我真的不认为这会导致这样的问题。我已尝试增加内存/超时,但仍然无法进入。500内部服务器错误实际上在我的页面上;我不知道Curl是否返回任何内容,但我知道如果我禁用“用户名”或尝试添加“密码”,我只会通过Curl得到一个正常错误,而不是一个内部服务器错误。此FTP登录没有密码 以下是我的主要脚本: function

好吧,这有点让我发疯。。。我在尝试使用Curl连接到外部FTP连接时一直收到一个内部服务器错误。我可以正常访问FTP,但不能通过Curl访问

我使用CodeIgniter作为包装器,但我真的不认为这会导致这样的问题。我已尝试增加内存/超时,但仍然无法进入。500内部服务器错误实际上在我的页面上;我不知道Curl是否返回任何内容,但我知道如果我禁用“用户名”或尝试添加“密码”,我只会通过Curl得到一个正常错误,而不是一个内部服务器错误。此FTP登录没有密码

以下是我的主要脚本:

function FTPScrape() {
    parent::Controller();
    $this->load->model("Curl_m");
}

function index() {
    ini_set('memory_limit', '70000000M');
    set_time_limit(0);
    define('COOKIES_DIR', 'cookies');
    define('RANDOM', COOKIES_DIR . '/' . md5(uniqid(mt_rand(), true)));
    $this->Curl_m->init(TRUE, RANDOM . '.txt');
    $this->Curl_m->start();

    $referer = '';
    $url = 'ftp://ftp.server.com/';
    $str = $this->Curl_m->ftp($url, 'user', '', __line__, $referer);
    print "<br><br><textarea cols=\"80\" rows=\"20\">{$str}</textarea><br><br>";
    $this->Curl_m->close();
}
有人知道我为什么会有这个问题吗

大部分脚本都是在我开始这个项目之前创建的,即Curl\m模型中的函数,我刚刚将这个类转换成了一个实际的codeigniter模型


如果我能找出如何防止它导致内部服务器错误,那么我应该能够很容易地修复其余的错误。

好吧,我找到了它不正常工作的原因。我试图增加允许的内存并允许无限超时,但我想我的服务器不想让我这么做

昨天和今天我都在尝试配置我的客户端设置的Amazon EC2帐户,以便将所有这些信息放在那里。之后,我再次测试了FTP刮板,它成功地连接并检索了我试图访问的数据。我的服务器实际上只是用于测试,不管怎样,最终的脚本将放在AmazonEC2上,但由于设置的复杂性,我推迟了它,因为我以前从未使用过AmazonEC2


无论如何,问题是脚本要么超时,要么超出了分配的内存。通过在更高端的服务器上设置,我使连接正常工作。显然,使用Curl登录FTP需要的资源/时间比我想象的要多。

您应该查看日志文件,了解500错误背后的原因。您是否通过HTTP代理进行FTP连接?无论哪种方式,提供完整的协议跟踪都可以让我们准确地看到发生了什么。Sabeen,我已经尝试检查错误日志,但与此特定错误完全无关。我的cPanel是针对Linux的Parallels Pro控制面板10.3.4。不确定这是否有帮助。丹,我不认为我是在通过HTTP代理进行FTP连接,但我不确定。。。老实说,我也不知道这意味着。。。我用PHP编程已经有一段时间了,但我对Curl还比较陌生。我也不知道如何进行协议跟踪。
function init($cookies = TRUE, $cookie = 'cookies.txt', $compression = '', $proxy = '') {
if(!is_dir('files')) {
    mkdir('files', 0777);
}
if(!is_dir('cookies')) {
    mkdir('cookies', 0777);
}
else if($dh = opendir('files/')) {
    while(($file = readdir($dh)) !== false) {
        if(is_file('files/'.$file)) {
            unlink('files/'.$file);
        }
    }
}
$this->user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 (.NET CLR 3.5.30729)';
$this->compression = $compression;
$this->proxy = $proxy;
$this->cookies = $cookies;
$this->filenumber = 0;
$this->follow_location = 1;
$this->headers_html = 0;
$this->binary = 0;
if($this->cookies == TRUE) {
    $this->cookie($cookie);
}
}

function start() {
    $this->process = curl_init();
}

function close() {
    curl_close($this->process);
}

function ftp($url, $user = '', $pass = '', $line_no = '', $referer = '') {
    return $this->execute($url, '', $line_no, $referer, $user, $pass);
}

function execute($url, $data = '', $line_no = '', $referer = '', $user = '', $pass = '') {
    if(isset($this->headers)) {
        unset($this->headers);
    }
    if(preg_match('/\w/xsi', $data)) {
        $type = 'POST';
    }
    else {
        $type = 'GET';
    }

    $host = parse_url($url);
    $this->headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
    $this->headers[] = 'Accept-Language: en-us,en;q=0.5';
    $this->headers[] = 'Accept-Encoding: gzip,deflate';
    $this->headers[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';
    $this->headers[] = 'Keep-Alive: 300';
    $this->headers[] = 'Connection: keep-alive';
    $this->headers[] = 'Expect:';
    if(preg_match('/\w/xsi',  $referer)) {
        $this->headers[] = 'Referer: ' . $referer . '';
    }

    if($type == 'POST') {
        if(isset($this->Content_type_change)) {
            $this->headers[] = 'Content-Type: ' . $this->Content_type_change . '';
            unset($this->Content_type_change);
        }
        else {
            $this->headers[] = 'Content-Type: application/x-www-form-urlencoded';
        }
        if(isset($this->extra_headings)) {
            $this->headers[] = $this->extra_headings;
        }
        if(!preg_match('/https:/xsi', $url)) {
            $this->headers[] = 'Content-Length: ' . strlen($data) . '';
        }
    }

    curl_setopt($this->process, CURLOPT_URL, $url);
    curl_setopt($this->process, CURLOPT_HTTPHEADER, $this->headers);
    curl_setopt($this->process, CURLOPT_HEADER, $this->headers_html);
    curl_setopt($this->process, CURLOPT_USERAGENT, $this->user_agent);
    if($this->cookies == TRUE) {
        curl_setopt($this->process, CURLOPT_COOKIEFILE, $this->cookie_file);
    }
    if($this->cookies == TRUE) {
        curl_setopt($this->process, CURLOPT_COOKIEJAR, $this->cookie_file);
    }
    curl_setopt($this->process, CURLOPT_ENCODING, $this->compression);
    curl_setopt($this->process, CURLOPT_CONNECTTIMEOUT, 0);
    curl_setopt($this->process, CURLOPT_TIMEOUT, 1200);
    curl_setopt($this->process, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($this->process, CURLOPT_RETURNTRANSFER, 1);

    if(strpos("ftp", $url) !== false) {
        curl_setopt($this->process, CURLOPT_FTPLISTONLY, 1);
    }
    if(!empty($user)) {
        $usrpwd = $user . ':' . $pass;
        curl_setopt($this->process, CURLOPT_USERPWD, $usrpwd);
    }

    if($this->binary == 1) {
        curl_setopt($this->process, CURLOPT_BINARYTRANSFER, 1);
    }

    if($this->follow_location == 1) {
        curl_setopt($this->process, CURLOPT_FOLLOWLOCATION, 1);
    }
    else {
        curl_setopt($this->process, CURLOPT_FOLLOWLOCATION, 0);
    }

    if($type == 'POST') {
        curl_setopt($this->process, CURLOPT_POSTFIELDS, $data);
        curl_setopt($this->process, CURLOPT_POST, 1);
    }

    if(preg_match("/\w/", $this->proxy)) {
        curl_setopt($this->process, CURLOPT_PROXY, $this->proxy);
    }

    $return = curl_exec($this->process);
    if($this->file_extension($url,$return) == 'jpg') {
        $fh = fopen('captcha.jpg', "w");
        fwrite($fh, $return);
        fclose($fh);
    }
    unset($this->headers);
    return $return;
}