---
title: How to Download and Migrate Attachments and Images from a Large WordPress.com Blog
date: 2012-10-31T07:32:37+00:00
modified: 2012-10-31T07:32:37+00:00
image:: https://kaspars.net/wp-content/uploads/2012/10/wordpress-import-images-curl-wget-attachments.png
permalink: https://kaspars.net/blog/download-migrate-attachments-images-from-large-wordpress-com-blog
post_type: post
author:
  name: Kaspars
  avatar: https://reverse.kaspars.net/gravatar/avatar/92bfcd3a8c3a21a033a6484d32c25a40b113ec6891f674336081513d5c98ef76?s=96&d=mm&r=g
post_tag:
  - How to
  - Snippet
  - Tool
category:
  - WordPress
---

# How to Download and Migrate Attachments and Images from a Large WordPress.com Blog

![](https://kaspars.net/wp-content/uploads/2012/10/wordpress-import-images-curl-wget-attachments.png?strip=all&quality=90&resize=500,362 "WordPress migrate download images and attachments from a large WordPress.com blog")The default WordPress importer can’t transfer more images than the `PHP`execution time allows it to, which makes it almost impossible to migrate a large WordPress.com site with lots of media assets and attachments.

I wrote a simple `PHP` script that extracts all attachment URLs from a WordPress export file and stores them in a text file with one URL per line:

```
$a = array();
$x = simplexml_load_file('export.xml');

foreach ( $x->channel->item as $item )
        if ( $wp = $item->children('http://wordpress.org/export/1.2/') )
                if ( $wp->post_type == 'attachment' )
                        $a[] = $wp->attachment_url;

file_put_contents( 'export_media.txt', implode( "\n", $a ) );
```

We can then use the `export_media.txt` file together with `wget` and `xargs` to download all attachements, like this:

```
$ xargs -n 1 wget -p -nc < urls.txt
```

or using `CURL`:

```
$ xargs -n 1 curl -O < export_media.txt
```

Note that the `wget` script will keep the correct folder structure.