Simple Hack to download files directly to your hosting space without SSH – PHP script

Simple Hack to download files directly to your hosting space without SSH – PHP script

I was moving my website from one host to other and the website size was very big that I could not download and upload the files to my new hosting provider. I had shared my story of the struggle I did here It took 16 hours to migrate a wordpress site where I used this trick to get my files downloaded from previous host to new host without downloading it on my laptop.

I’m sharing this PHP script which invokes system functions on server to download files. This is the most handy script when you don’t have SSH access on the server. It’s kinda a hack as you don’t have permission to use SSH but still you are able to do your job with PHP. Many host can block specific functions of PHP but this works in most cases and this helped me too.

You need to create a folder where you want to download the file and place below script in the folder. Save the changes and visit this php page from the browser. In the url field enter the url to the file you want to download and hit submit, now wait for a few minutes and your file will be ready. 🙂


<html>
<form method="post">
<input name="url" size="50" />
<input name="submit" type="submit" />
</form>
<?php
    set_time_limit (24 * 60 * 60);
 
    if (!isset($_POST['submit'])) die();
 
    // folder to save file to
    $dest_fldr = 'downloads/';
 
    $url = $_POST['url'];
    $newfname = $dest_fldr . basename($url);
 
    $file = fopen ($url, "rb");
    if ($file) {
      $newf = fopen ($newfname, "wb");
 
      if ($newf)
      while(!feof($file)) {
        fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
      }
    }
 
    if ($file) {
      fclose($file);
    }
 
    if ($newf) {
      fclose($newf);
    }
?>

Hope this will help.

Unzip files with PHP on hosting space.



© 2017. All rights reserved.