API16

JFTP/connect

From Joomla! Documentation

< API16:JFTP

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Method to connect to a FTP server


<! removed transcluded page call, red link never existed >

Syntax[edit]

connect($host= '127.0.0.1', $port=21)
Parameter Name Default Value Description
$host '127.0.0.1' $host Host to connect to [Default: 127.0.0.1]
$port 21 $port Port to connect on [Default: port 21]

Returns[edit]

boolean True if successful

Defined in[edit]

libraries/joomla/client/ftp.php

Importing[edit]

jimport( 'joomla.client.ftp' );

Source Body[edit]

function connect($host = '127.0.0.1', $port = 21) {

        // Initialise variables.
        $errno = null;
        $err = null;

        // If already connected, return
        if (is_resource($this->_conn)) {
                return true;
        }

        // If native FTP support is enabled lets use it...
        if (FTP_NATIVE) {
                $this->_conn = @ftp_connect($host, $port, $this->_timeout);
                if ($this->_conn === false) {
                        JError::raiseWarning('30', 'JFTP::connect: Could not connect to host "'.$host.'" on port '.$port);
                        return false;
                }
                // Set the timeout for this connection
                ftp_set_option($this->_conn, FTP_TIMEOUT_SEC, $this->_timeout);
                return true;
        }

        // Connect to the FTP server.
        $this->_conn = @ fsockopen($host, $port, $errno, $err, $this->_timeout);
        if (!$this->_conn) {
                JError::raiseWarning('30', 'JFTP::connect: Could not connect to host "'.$host.'" on port '.$port, 'Socket error number '.$errno.' and error message: '.$err);
                return false;
        }

        // Set the timeout for this connection
        socket_set_timeout($this->_conn, $this->_timeout);

        // Check for welcome response code
        if (!$this->_verifyResponse(220)) {
                JError::raiseWarning('35', 'JFTP::connect: Bad response', 'Server response: '.$this->_response.' [Expected: 220]');
                return false;
        }

        return true;
}


<! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]