Upload Images to Remote Server in WordPress

I am using WordPress Media Uploader to upload images and I was wondering if there is a way to make it upload to my remote server instead of my local server? Example: My wordpress website is hosted on Server A and I want to want to use the media uploader to upload images to Server B instead of Server A.

Why do this ?

1. If your diskspace is too small

Most large hosting providers allow unlimited storage and bandwidth. But as i have said in this article: 4 Heartbreaking Truth of Shared Hosting, Unlimited means the limited and there are many providers limit disk space and the number of files with Shared Hosting packages. So you can’t store too much files or big size files on your hosting.

2. “Make your site run faster”

If your website has large traffic that all images and files are only stored on one server (assuming server A), it will certainly be very bandwidth intensive. If the image and attach files are stored on another server (server B) , the server A will be only used to run your website , while the image files will be downloaded from server B , significantly reduced bandwidth for server A.

On the other hand, when the visitors go to your website , the browser will load simultaneously the codes ( php files , js files , css files … ) from server A and images from server B. They will feel your website is faster because of when the codes are finished processing your website will display whether the images haven’t been finished loading (like lazy loading).

How do this ?

Ethan Joachim Eldridge has just built a plugin that does this. It is not perfect but it do its job.

You can find it in his Github: https://github.com/pontusab/wp-ftp-media-library

Step 1: Download this plugin by clicking Download ZIP button at the right sidebar.

WP FTP Media Library

Download WP FTP Media Library

Step 2: You need to change some things within the file on the row 28:

* Change this to match your server
* You only need to change the those with (*)
* If marked with (-) its optional
$settings = array(
'host'      =>    'IP or Hostname',              // * the ftp-server hostname
'user'      =>    'Username',                 // * ftp-user
'pass'      =>    'Password',                     // * ftp-password
'cdn'     =>    'cdn.example.com',            // * This have to be a pointed domain or subdomain to the root of the uploads
'path'      =>    '/',                         // - ftp-path, default is root (/). Change here and add the dir on the ftp-server,
'base'      =>    $upload_dir['basedir']      // Basedir on local

Step 3: Upload to plugin folder and activate it in your wp-admin.

What this plugin does is, it changes the upload structure from /year/month to only upload on the local machine in our case Server A. Then it uses php to connect to the ftp via: ftp_connect. The function fires when wp_generate_attachment_metadata runs. It then run a check in the upload folder to see if there are any images, if so it will upload them all to the ftp-server via ftp_put. When the upload is completed the files will be removed from the local machine using the function unlink.

Then the plugin changes the url of the images to the “public” ip or hostname pointed to the ftp-server. I suggest using something like static.mydomain.com or cdn.mydomai.com. They need to be pointed to the ftp-server (Server B) this enables you to load the images from the ftp-server.

As the other members say you shouldent use an ftp-server for this, its better with an real cdn, Mounted by fuse or something like Amazon S3.

Expansion, i want to introduce a wordpress plugin helps you to upload files from remote server to your server. That is Remote Upload – WordPress Plugin. With this plugin you can upload .jeg, .zip, ,rar, .flv, .swf, .mp3, .mp4, .png, .gif, .jpeg, .pdf & etc. File types to you site Directly from the net. You just have to put the file url in the the url box and it will automatically download the file or files to your site and list the them in your media library.

You don’t have to waste your time in tiresome saving of images & files from the net and upload them to your blog again. And if you have a slow connection then this is the must have tool for you.

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments
eHDF dedicated server
5 years ago

This is by far the most detailed and effective post on “remote server image uploads” that I have read till date. I have been facing the problem with different image formats and now you nailed the problem.

4 years ago

This plugin is working fine. But when I m going into wp media and trying to edit any images its not allowing me to do that and saying ‘Image data does not exist. Please re-upload the image;.

4 years ago

My server doesn’t allow FTP, but support SFTP, do you have solution for this? Thanks!

Would love your thoughts, please comment.x