Title: WP_Filesystem_FTPext::copy
Published: April 25, 2014
Last modified: May 20, 2026

---

# WP_Filesystem_FTPext::copy( string $source, string $destination, bool $overwrite = false, int|false $mode = false ): bool

## In this article

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

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

Copies a file.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpext/copy/?output_format=md#parameters)󠁿

 `$source`stringrequired

Path to the source file.

`$destination`stringrequired

Path to the destination file.

`$overwrite`booloptional

Whether to overwrite the destination file if it exists.

Default:`false`

`$mode`int|falseoptional

The permissions as octal number, usually 0644 for files, 0755 for dirs.

Default:`false`

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

 bool True on success, false on failure.

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

    ```php
    public function copy( $source, $destination, $overwrite = false, $mode = false ) {
    	if ( ! $overwrite && $this->exists( $destination ) ) {
    		return false;
    	}

    	$content = $this->get_contents( $source );

    	if ( false === $content ) {
    		return false;
    	}

    	return $this->put_contents( $destination, $content, $mode );
    }
    ```

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

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

| Uses | Description | 
| [WP_Filesystem_FTPext::exists()](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpext/exists/)`wp-admin/includes/class-wp-filesystem-ftpext.php` |

Checks if a file or directory exists.

  | 
| [WP_Filesystem_FTPext::get_contents()](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpext/get_contents/)`wp-admin/includes/class-wp-filesystem-ftpext.php` |

Reads entire file into a string.

  | 
| [WP_Filesystem_FTPext::put_contents()](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpext/put_contents/)`wp-admin/includes/class-wp-filesystem-ftpext.php` |

Writes a string to a file.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_ftpext/copy/?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_ftpext%2Fcopy%2F)
before being able to contribute a note or feedback.