sajad torkamani

When cloning a WordPress project between local and remote machines, you’ll want to either:

  1. Transfer media files from your local machine to remote machine.
  2. Transfer media files from your remote machine to local machine.

Let’s consider an approach you might take.

Transfer media files from your local machine to remote machine

Create a script and make it executable:

touch scripts/export_uploads
chmod +x scripts/export_uploads

Set contents to:

#!/usr/bin/env bash

localUploadsPath='/absolute-path-to-local-wp-content-uploads'
remoteUploadsPath='<ssh-alias>:/absolute-path-to-local-wp-content-uploads'

rsync -LPa $localUploadsPath $remoteUploadsPath
echo "Finished exporting uploads to: $remoteUploadsPath";

Notice the <ssh-alias> placeholder in the remote upload path. You’ll need to configure an SSH alias before proceeding.

Execute:

./scripts/export_uploads

Transfer media files from remote machine to local machine

Create a script and make it executable:

touch scripts/import_uploads
chmod +x scripts/import_uploads

Set contents to:

#!/usr/bin/env bash

remoteUploadsPath='<ssh-alias>:/absolute-path-to-local-wp-content-uploads'
localUploadsPath='/absolute-path-to-local-wp-content-uploads'

rsync -LPa $remoteUploadsPath $localUploadsPath
echo "Finished importing uploads to: $localUploadsPath";

Execute:

./scripts/import_uploads

Tagged: WordPress

Leave a comment

Your email address will not be published. Required fields are marked *