API16

Difference between revisions of "JFTP/connect"

From Joomla! Documentation

< API16:JFTP
(New page: ===Description=== Method to connect to a FTP server <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> ...)
 
m (preparing for archive only)
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
Method to connect to a FTP server
 
Method to connect to a FTP server
  
<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[Description:JFTP/connect|Edit Descripton]]<nowiki>]</nowiki>
 
</span>
 
  
{{Description:JFTP/connect}}
+
 
 +
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 79: Line 77:
 
</source>
 
</source>
  
<span class="editsection" style="font-size:76%;">
+
 
<nowiki>[</nowiki>[[SeeAlso:JFTP/connect|Edit See Also]]<nowiki>]</nowiki>
+
<! removed transcluded page call, red link never existed >
</span>
 
{{SeeAlso:JFTP/connect}}
 
  
 
===Examples===
 
===Examples===
<CodeExamplesForm />
+
=== Code Examples ===
 
<dpl>
 
<dpl>
 
  noresultsheader=\n
 
  noresultsheader=\n
 
  category=connect
 
  category=connect
 
  category=JFTP
 
  category=JFTP
  category=CodeExample
+
  namespace=CodeExample
 
  category=MethodExample
 
  category=MethodExample
 
  include=*
 
  include=*
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 20:38, 24 March 2017

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]