WP_Filesystem_SSH2::move()publicWP 2.7.0

Moves a file or directory.

After moving files or directories, OPcache will need to be invalidated.

If moving a directory fails, copy_dir() be used for a recursive copy.

Use move_dir() moving directories with OPcache invalidation and a fallback to copy_dir().

Method of the class: WP_Filesystem_SSH2{}

No Hooks.

Return

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

Usage

$WP_Filesystem_SSH2 = new WP_Filesystem_SSH2();
$WP_Filesystem_SSH2->move( $source, $destination, $overwrite );
$source(string) (required)
Path to the source file or directory.
$destination(string) (required)
Path to the destination file or directory.
$overwrite(true|false)
Whether to overwrite the destination if it exists.
Default: false

Changelog

Since 2.7.0 Introduced.

WP_Filesystem_SSH2::move() code WP 6.6.2

public function move( $source, $destination, $overwrite = false ) {
	if ( $this->exists( $destination ) ) {
		if ( $overwrite ) {
			// We need to remove the destination before we can rename the source.
			$this->delete( $destination, false, 'f' );
		} else {
			// If we're not overwriting, the rename will fail, so return early.
			return false;
		}
	}

	return ssh2_sftp_rename( $this->sftp_link, $source, $destination );
}