WP_Filesystem_FTPext::connect()publicWP 2.5.0

Connects filesystem.

Method of the class: WP_Filesystem_FTPext{}

No Hooks.

Return

true|false. True on success, false on failure.

Usage

$WP_Filesystem_FTPext = new WP_Filesystem_FTPext();
$WP_Filesystem_FTPext->connect();

Changelog

Since 2.5.0 Introduced.

WP_Filesystem_FTPext::connect() code WP 6.5.2

public function connect() {
	if ( isset( $this->options['ssl'] ) && $this->options['ssl'] && function_exists( 'ftp_ssl_connect' ) ) {
		$this->link = @ftp_ssl_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT );
	} else {
		$this->link = @ftp_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT );
	}

	if ( ! $this->link ) {
		$this->errors->add(
			'connect',
			sprintf(
				/* translators: %s: hostname:port */
				__( 'Failed to connect to FTP Server %s' ),
				$this->options['hostname'] . ':' . $this->options['port']
			)
		);

		return false;
	}

	if ( ! @ftp_login( $this->link, $this->options['username'], $this->options['password'] ) ) {
		$this->errors->add(
			'auth',
			sprintf(
				/* translators: %s: Username. */
				__( 'Username/Password incorrect for %s' ),
				$this->options['username']
			)
		);

		return false;
	}

	// Set the connection to use Passive FTP.
	ftp_pasv( $this->link, true );

	if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) {
		@ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT );
	}

	return true;
}