Server to Server > Retrieve and extract a remote zip file to local server directory
<p>I have a wp plugin file on server B who's purpose is to retrieve a zip file from a remote server A. </p>

<p>Once Server B receives the zip file, it should extract the contents and copy the files into a specific folder on server B overwriting any existing files.</p>

<p>I have some code below that I've borrowed from a file that uses and uploader to do the same thing and I'd just like to redo it for the automated server to server procedure described above. But I'm getting a fatal error when trying to Activate this plugin.</p>

<pre><code>function remote_init() 
{
    openZip('http://myserver.com/upgrade.zip');
    $target = ABSPATH.'wp-content/themes/mytheme/';
}


function openZip($file_to_open, $debug = false) { 
    global $target;
    $file = realpath('/tmp/'.md5($file_to_open).'.zip');
</code></pre>

<p>//$file is always empty. can't use realpath in this case. What to do?</p>

<pre><code>    $client = curl_init($file_to_open);
    curl_setopt(CURLOPT_RETURNTRANSFER, 1);

    $fileData = curl_exec($client);

    file_put_contents($file, $fileData);

    $zip = new ZipArchive();  
    $x = $zip-&gt;open($file);  
    if($x === true) {  
        $zip-&gt;extractTo($target);  
        $zip-&gt;close();  

        unlink($file);  
    } else {
        if($debug !== true) {
            unlink($file);
        }  
        die("There was a problem. Please try again!");  
    }  
} 


add_action( 'init','remote_init');
</code></pre>
