Title: WP_Filesystem_ftpsockets::connect
Published: April 25, 2014
Last modified: February 24, 2026

---

# WP_Filesystem_ftpsockets::connect(): bool

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpsockets/connect/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpsockets/connect/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpsockets/connect/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpsockets/connect/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpsockets/connect/?output_format=md#wp--skip-link--target)

Connects filesystem.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpsockets/connect/?output_format=md#return)󠁿

 bool True on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpsockets/connect/?output_format=md#source)󠁿

    ```php
    public function connect() {
    	if ( ! $this->ftp ) {
    		return false;
    	}

    	$this->ftp->SetTimeout( FS_CONNECT_TIMEOUT );

    	if ( ! $this->ftp->SetServer( $this->options['hostname'], $this->options['port'] ) ) {
    		$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 ( ! $this->ftp->connect() ) {
    		$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 ( ! $this->ftp->login( $this->options['username'], $this->options['password'] ) ) {
    		$this->errors->add(
    			'auth',
    			sprintf(
    				/* translators: %s: Username. */
    				__( 'Username/Password incorrect for %s' ),
    				$this->options['username']
    			)
    		);

    		return false;
    	}

    	$this->ftp->SetType( FTP_BINARY );
    	$this->ftp->Passive( true );
    	$this->ftp->SetTimeout( FS_TIMEOUT );

    	return true;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php#L75)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php#L75-L126)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpsockets/connect/?output_format=md#related)󠁿

| Uses | Description | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpsockets/connect/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_filesystem_ftpsockets%2Fconnect%2F)
before being able to contribute a note or feedback.