When working on Adobe Commerce (Magento 2) Cloud projects, there are times when your product images or other media assets in pub/media need to be synced across environments — for example, from production to staging or local.
This tutorial will show you how to do that using the powerful rsync command.
Step 1: Understand the Use Case
Magento stores all product images inside this directory:
pub/media/catalog/product/These images are not stored in the database, so when you set up a staging or local environment, the media folder might be missing.
To fix that, we’ll use rsync to copy media from one environment (like production) to another (like staging or local).
Step 2: Get SSH Access to Your Cloud Environment
First, log in to your project using the Magento Cloud CLI:
magento-cloud loginList all your available projects:
magento-cloud project:listCopy your desired Project ID. It will look something like:
phoshzb26izzz
From now on, we’ll refer to it as your_project_id.
Step 3: List and Identify Environments
Now list all environments for your project:
magento-cloud environment:list -p your_project_idTypical output:
* master (production)
staging
developmentYou’ll need the environment name (e.g. staging) in the next steps.
Step 4: Find the SSH Alias for Your Environment
Get the SSH alias (used in rsync) with:
magento-cloud ssh -p your_project_id -e staging --pipeYou’ll get something like:
1.ent-phoshzb26izzz-staging2-5zxmgzy@ssh.us-a1.magento.cloudThis will be used as the destination in the rsync command.
Step 5: Sync Local Media to Staging (or Any Environment)
Use the following command to sync images from your local machine to the cloud environment:
rsync -azvP pub/media/catalog/product/ 1.ent-phoshzb26izzz-staging2-5zxmgzy@ssh.us-a1.magento.cloud:pub/media/catalog/product/Replace the 1.ent-... alias with the one from your project.
Optional: Dry Run First
Test the command without actually copying files:
rsync -azvP --dry-run pub/media/catalog/product/ 1.ent-phoshzb26izzz-staging-5zxmgzy@ssh.us-a1.magento.cloud:pub/media/catalog/product/You can also copy files directly from one server to another, such as from production to staging, without needing to download them locally.
Simply SSH into the source environment (e.g., production), and then run the
rsynccommand using the destination environment’s SSH alias as the target.This allows for a direct server-to-server file transfer, which is faster and more efficient.
Bonus – Sync from Cloud to Local
If you want to pull images from cloud → local instead, just reverse the direction:
rsync -azvP 1.ent-phoshzb26izzz-staging-5zxmgzy@ssh.us-a1.magento.cloud:pub/media/catalog/product/ pub/media/catalog/product/Step 6: SSH into the Cloud Environment to Verify
After syncing, SSH into the environment to verify the files:
magento-cloud ssh -p your_project_id -e stagingThen check the product image directory:
cd pub/media/catalog/product/
ls -alStep 7: Clean Cache
php bin/magento cache:clean
php bin/magento cache:flushIf using Fastly or Varnish, you may need to clear those caches as well.
That’s it!
So, Using rsync along with Magento Cloud CLI (magento-cloud) helps you manage media files efficiently across environments.
You may also like,
Backups (snapshots) in Magento Commerce Cloud
Adobe Commerce Cloud Project Structure
Thank you, See you in the next blog.




Leave a Comment