Transfer WordPress media files between servers
12 March 2022 (Updated 12 March 2022)
When cloning a WordPress project between local and remote machines, you’ll want to either:
- Transfer media files from your local machine to remote machine.
- 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
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment