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
scp -v -r ~/Downloads [email protected]:/root/Tool/Downloads
2. In the remote server, install wp-cli:
/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
3. Use WP-CLI to upload all media files in the Downloads folder
/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
That’s all. Now all your files should be imported inside your WordPress media library.