function _connect($host, $port)
 {
     $this->SendMSG("Creating ftp connection");
     $sock = ftp_connect(convert_host_to_idna($host), $port, $this->_timeout);
     if (!$sock) {
         $this->PushError('_connect', 'ftp connect failed');
         return false;
     }
     $this->_connected = true;
     return $sock;
 }
function fsockopen_idna($host, $port, $timeout)
{
    $host = convert_host_to_idna($host);
    $fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
    return array($fp, $errno, $errstr, $host);
}
 function _httpsrequest($url, $URI, $http_method, $content_type = "", $body = "")
 {
     $temp_dir = "";
     $cmdline_params = "";
     if ($this->passcookies && $this->_redirectaddr) {
         $this->setcookies();
     }
     $headers = array();
     $URI_PARTS = parse_url($URI);
     if (empty($url)) {
         $url = "/";
     }
     // GET ... header not needed for curl
     //$headers[] = $http_method." ".$url." ".$this->_httpversion;
     if (!empty($this->agent)) {
         $headers[] = "User-Agent: " . $this->agent;
     }
     if (!empty($this->host)) {
         if (!empty($this->port)) {
             $headers[] = "Host: " . convert_host_to_idna($this->host) . ":" . $this->port;
         } else {
             $headers[] = "Host: " . convert_host_to_idna($this->host);
         }
     }
     if (!empty($this->accept)) {
         $headers[] = "Accept: " . $this->accept;
     }
     if (!empty($this->referer)) {
         $headers[] = "Referer: " . $this->referer;
     }
     if (!empty($this->cookies)) {
         if (!is_array($this->cookies)) {
             $this->cookies = (array) $this->cookies;
         }
         reset($this->cookies);
         if (count($this->cookies) > 0) {
             $cookie_str = 'Cookie: ';
             foreach ($this->cookies as $cookieKey => $cookieVal) {
                 $cookie_str .= $cookieKey . "=" . urlencode($cookieVal) . "; ";
             }
             $headers[] = substr($cookie_str, 0, -2);
         }
     }
     if (!empty($this->rawheaders)) {
         if (!is_array($this->rawheaders)) {
             $this->rawheaders = (array) $this->rawheaders;
         }
         while (list($headerKey, $headerVal) = each($this->rawheaders)) {
             $headers[] = $headerKey . ": " . $headerVal;
         }
     }
     if (!empty($content_type)) {
         if ($content_type == "multipart/form-data") {
             $headers[] = "Content-type: {$content_type}; boundary=" . $this->_mime_boundary;
         } else {
             $headers[] = "Content-type: {$content_type}";
         }
     }
     if (!empty($body)) {
         $headers[] = "Content-length: " . strlen($body);
     }
     if (!empty($this->user) || !empty($this->pass)) {
         $headers[] = "Authorization: BASIC " . base64_encode($this->user . ":" . $this->pass);
     }
     for ($curr_header = 0; $curr_header < count($headers); $curr_header++) {
         $safer_header = strtr($headers[$curr_header], "\"", " ");
         $cmdline_params .= " -H \"" . $safer_header . "\"";
     }
     if (!empty($body)) {
         $cmdline_params .= " -d \"{$body}\"";
     }
     if ($this->read_timeout > 0) {
         $cmdline_params .= " -m " . $this->read_timeout;
     }
     $headerfile = tempnam($temp_dir, "sno");
     exec($this->curl_path . " -k -D \"{$headerfile}\"" . $cmdline_params . " \"" . escapeshellcmd($URI) . "\"", $results, $return);
     if ($return) {
         $this->error = "Error: cURL could not retrieve the document, error {$return}.";
         return false;
     }
     $results = implode("\r\n", $results);
     $result_headers = file("{$headerfile}");
     $this->_redirectaddr = false;
     unset($this->headers);
     for ($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) {
         // if a header begins with Location: or URI:, set the redirect
         if (preg_match("/^(Location:|URI:)/i", $result_headers[$currentHeader])) {
             // get URL portion of the redirect
             preg_match("/^(Location:|URI:)[ ]+(.*)/", chop($result_headers[$currentHeader]), $matches);
             // look for :// in the Location header to see if hostname is included
             if (!preg_match("|\\:\\/\\/|", $matches[2])) {
                 // no host in the path, so prepend
                 $this->_redirectaddr = $URI_PARTS["scheme"] . "://" . $this->host . ":" . $this->port;
                 // eliminate double slash
                 if (!preg_match("|^/|", $matches[2])) {
                     $this->_redirectaddr .= "/" . $matches[2];
                 } else {
                     $this->_redirectaddr .= $matches[2];
                 }
             } else {
                 $this->_redirectaddr = $matches[2];
             }
         }
         if (preg_match("|^HTTP/|", $result_headers[$currentHeader])) {
             if (preg_match("|^HTTP/[^\\s]*\\s(.*?)\\s|", $result_headers[$currentHeader], $status)) {
                 $this->status = $status[1];
             }
             $this->response_code = $result_headers[$currentHeader];
         }
         $this->headers[] = $result_headers[$currentHeader];
     }
     // check if there is a a redirect meta tag
     if (preg_match("'<meta[\\s]*http-equiv[^>]*?content[\\s]*=[\\s]*[\"\\']?\\d+;[\\s]*URL[\\s]*=[\\s]*([^\"\\']*?)[\"\\']?>'i", $results, $match)) {
         $this->_redirectaddr = $this->_expandlinks($match[1], $URI);
     }
     // have we hit our frame depth and is there frame src to fetch?
     if ($this->_framedepth < $this->maxframes && preg_match_all("'<frame\\s+.*src[\\s]*=[\\'\"]?([^\\'\"\\>]+)'i", $results, $match)) {
         $this->results[] = $results;
         for ($x = 0; $x < count($match[1]); $x++) {
             $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"] . "://" . $this->host);
         }
     } elseif (is_array($this->results)) {
         $this->results[] = $results;
     } else {
         $this->results = $results;
     }
     unlink("{$headerfile}");
     return true;
 }