How to Bulk Upload Media Files Using WordPress CLI

Most hosting providers set a maximum file upload in WordPress ranging from 2 to 64MB. This is a huge restriction especially when you want to upload a lot of large files. Even if you manage to increase the upload size limit, big GIF and video files often cause timeout error when uploading through WordPress media library.

In this article, we will show how you can easily upload multiple file attachments from your local files directly to your WordPress media library using WordPress CLI.

1. Use SCP command to securely transfer files

To copy an entire directory from one host to another, use the r switch and specify the destination directory. In this example, we upload all files on Downloads to the sever’s root/Tool folder:

scp -v -r ~/Downloads root@192.1.1.8:/root/Tool/Downloads

2. In the remote server, install wp-cli:

Under /root/Tool folder, run these 2 commands:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar

Reference: https://wp-cli.org/

3. Use WP-CLI to upload all media files in the Downloads folder

Under /root/Tool folder, run this command:

./wp-cli.phar media import ./Downloads/* --path=/home/pda/webapps/pda.com/

--path=<path>: Path to the root folder of your WordPress site

Reference: https://developer.wordpress.org/cli/commands/media/import/

That’s all. Now all your files should be imported inside your WordPress media library.