For Magento 2 there is a open source module which does exactly this.
If you are on Linux, a more generic solution seems to be possible, using http and union fuse file systems. This could work on different Shop- and CMS systems such as Shopware, TYPO3 and so on.
The following example was tested on Ubuntu 20.04
First install the required packages
apt install httpdirfs unionfs-fuse
We assume, the production server uses Apache. In the next step we enable directory listing, but only for a certain - secret - user agent. Make sure to replace "ThisIsSecret" by your secret.
<If "%{HTTP_USER_AGENT} == 'ThisIsSecret'">
Options +Indexes +MultiViews
AllowOverride None
</If>
<Else>
Options -Indexes -MultiViews +FollowSymLinks
AllowOverride All
</Else>
Go to your local development directory and move the current media
directory:
cd /home/me/projects/example.com/public
mv media media_local
Now httpdirfs
is used to mount the server's directory via HTTP. httpdirfs
parses the directory listing and lets you see the remote files. Editing is not possible.
mkdir media_remote
httpdirfs --cache --user-agent ThisIsSecret https://example.com/media/ media_remote
Next, we use unionfs
with the CopyOnWrite (cow
) option to be able to still write to the media folder.
mkdir media
unionfs-fuse -o cow media_local=RW:media_remote=RO media
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…