_data_close example

function fget($fp$remotefile$rest=0) {
        if($this->_can_restore and $rest!=0) fseek($fp$rest);
        $pi=pathinfo($remotefile);
        if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"])$this->AutoAsciiExt))) $mode=FTP_ASCII;
        else $mode=FTP_BINARY;
        if(!$this->_data_prepare($mode)) {
            return FALSE;
        }
        if($this->_can_restore and $rest!=0) $this->restore($rest);
        if(!$this->_exec("RETR ".$remotefile, "get")) {
            $this->_data_close();
            return FALSE;
        }
        if(!$this->_checkCode()) {
            $this->_data_close();
            return FALSE;
        }
        $out=$this->_data_read($mode$fp);
        $this->_data_close();
        if(!$this->_readmsg()) return FALSE;
        if(!$this->_checkCode()) return FALSE;
        return $out;
    }
return FALSE;
        }
        $this->_lastaction=time();
        if(!$this->_readmsg($fnction)) return FALSE;
        return TRUE;
    }

    function _data_prepare($mode=FTP_ASCII) {
        if(!$this->_settype($mode)) return FALSE;
        if($this->_passive) {
            if(!$this->_exec("PASV", "pasv")) {
                $this->_data_close();
                return FALSE;
            }
            if(!$this->_checkCode()) {
                $this->_data_close();
                return FALSE;
            }
            $ip_port = explode(",", preg_replace("/^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*$/s", "\\1", $this->_message));
            $this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
            $this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
            $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
            $this->_ftp_data_sock=@fsockopen($this->_datahost, $this->_dataport, $errno$errstr$this->_timeout);
            


    function _data_prepare($mode=FTP_ASCII) {
        if(!$this->_settype($mode)) return FALSE;
        $this->SendMSG("Creating data socket");
        $this->_ftp_data_sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if ($this->_ftp_data_sock < 0) {
            $this->PushError('_data_prepare','socket create failed',socket_strerror(socket_last_error($this->_ftp_data_sock)));
            return FALSE;
        }
        if(!$this->_settimeout($this->_ftp_data_sock)) {
            $this->_data_close();
            return FALSE;
        }
        if($this->_passive) {
            if(!$this->_exec("PASV", "pasv")) {
                $this->_data_close();
                return FALSE;
            }
            if(!$this->_checkCode()) {
                $this->_data_close();
                return FALSE;
            }
            
Home | Imprint | This part of the site doesn't use cookies.