API15:JFTP/connect
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Method to connect to a FTP server
Syntax
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
boolean True if successful
Defined in
libraries/joomla/client/ftp.php
Importing
jimport( 'joomla.client.ftp' );
Source Body
function connect($host = '127.0.0.1', $port = 21) { // Initialize 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; }
[Edit See Also] SeeAlso:JFTP/connect
Examples
<CodeExamplesForm />
