src/Clients/FtpClient.php
public function connect($host = '127.0.0.1', $port = 21)
	{
		$errno = null;
		$err   = null;

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

		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			$this->conn = @ftp_connect($host, $port, $this->timeout);

			if ($this->conn === false)
			{
				throw new FilesystemException(sprintf('%1$s: Could not connect to host " %2$s " on port " %3$s "', __METHOD__, $host, $port));
			}

			// 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)
		{
			throw new FilesystemException(
				sprintf(
					'%1$s: Could not connect to host " %2$s " on port " %3$s ". Socket error number: %4$s and error message: %5$s',
					__METHOD__,
					$host,
					$port,
					$errno,
					$err
				)
			);
		}

		// Set the timeout for this connection
		socket_set_timeout($this->conn, $this->timeout, 0);

		// Check for welcome response code
		if (!$this->_verifyResponse(220))
		{
			throw new FilesystemException(sprintf('%1$s: Bad response. Server response: %2$s [Expected: 220]', __METHOD__, $this->response));
		}

		return true;
	}
public function connect($host = '127.0.0.1', $port = 21)
	{
		$errno = null;
		$err   = null;

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

		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			$this->conn = @ftp_connect($host, $port, $this->timeout);

			if ($this->conn === false)
			{
				throw new FilesystemException(sprintf('%1$s: Could not connect to host " %2$s " on port " %3$s "', __METHOD__, $host, $port));
			}

			// 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)
		{
			throw new FilesystemException(
				sprintf(
					'%1$s: Could not connect to host " %2$s " on port " %3$s ". Socket error number: %4$s and error message: %5$s',
					__METHOD__,
					$host,
					$port,
					$errno,
					$err
				)
			);
		}

		// Set the timeout for this connection
		socket_set_timeout($this->conn, $this->timeout, 0);

		// Check for welcome response code
		if (!$this->_verifyResponse(220))
		{
			throw new FilesystemException(sprintf('%1$s: Bad response. Server response: %2$s [Expected: 220]', __METHOD__, $this->response));
		}

		return true;
	}
public function connect ( $ host = '127.0.0.1' , $ port = 21 ) { $ errno = null ; $ err = null ; // If already connected, return if ( \ is_resource ( $ this -> conn ) ) { return true ; } // If native FTP support is enabled let's use it... if ( FTP_NATIVE ) { $ this -> conn = @ ftp_connect ( $ host , $ port , $ this -> timeout ) ; if ( $ this -> conn === false ) { throw new FilesystemException ( sprintf ( '%1$s: Could not connect to host " %2$s " on port " %3$s "' , __METHOD__ , $ host , $ port ) ) ; } // 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 ) { throw new FilesystemException ( sprintf ( '%1$s: Could not connect to host " %2$s " on port " %3$s ". Socket error number: %4$s and error message: %5$s' , __METHOD__ , $ host , $ port , $ errno , $ err ) ) ; } // Set the timeout for this connection socket_set_timeout ( $ this -> conn , $ this -> timeout , 0 ) ; // Check for welcome response code if ( ! $ this -> _verifyResponse ( 220 ) ) { throw new FilesystemException ( sprintf ( '%1$s: Bad response. Server response: %2$s [Expected: 220]' , __METHOD__ , $ this -> response ) ) ; } return true ; }
Method to connect to a FTP server

@param   string   $host  Host to connect to [Default: 127.0.0.1]
@param   integer  $port  Port to connect on [Default: port 21]

@return  boolean  True if successful

@since   1.0
@throws  FilesystemException
Method to connect to a FTP server