3

I'd like to download files directly to a hosted server, whether it's one I set up myself or a hosted service like Dropbox.

For example, when I download a podcast, instead of downloading it to my computer then uploading it to the server, how can I have it download directly to the cloud. My interest here is reducing the traffic I'm using over a metered data plan on my laptop, so I don't want my computer acting as a physical intermediary caching the file.

Ideally, there would be some way for me to have a download link and tell it to go directly to my server. How can I accomplish this?

I realize that this question is potentially involving a "webapp" and it is potentially involving "server administration" and since my goal is to cut my computer out of the loop I can see people saying this is off-topic and should be on another site. My issue is this: I don't know if this is going to be a webapp solution or a server solution but I do know regardless I'm going to be using a computer to get it done and I am replacing a function that's currently done on my computer so I figured I'd ask it here. If I was wrong and this definitely should be at webapps feel free to let me know or just migrate it.

4 Answers 4

6

You could:

  • VNC into the server, load a browser, and download the file.
  • SSH into the server, and do essentially the same but using the CLI (curl? wget?). It is possible to use SSH to execute a remote command; see ulidtko's answer for an example of this.
  • Create an application on the server that can queue up URL's of file downloads (a web service?). It can poll the queue, downloading each file until the queue is empty.
3

With CLI this is incredibly easy.

$ URL="http://upload.wikimedia.org/wikipedia/commons/1/15/Red_Apple.jpg"
$ ssh user@remote-host 'wget $URL'

--2011-02-05 11:15:10--  http://upload.wikimedia.org/wikipedia/commons/1/15/Red_Apple.jpg
Resolving upload.wikimedia.org... 91.198.174.234
Connecting to upload.wikimedia.org|91.198.174.234|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 576216 (563K) [image/jpeg]
Saving to: `Red_Apple.jpg'

     0K .......... .......... .......... .......... ..........  8%  327K 2s
    50K .......... .......... .......... .......... .......... 17%  668K 1s
   100K .......... .......... .......... .......... .......... 26% 1.23M 1s
   150K .......... .......... .......... .......... .......... 35% 1.23M 1s
   200K .......... .......... .......... .......... .......... 44%  697K 0s
   250K .......... .......... .......... .......... .......... 53% 1.15M 0s
   300K .......... .......... .......... .......... .......... 62%  707K 0s
   350K .......... .......... .......... .......... .......... 71% 1.13M 0s
   400K .......... .......... .......... .......... .......... 79%  713K 0s
   450K .......... .......... .......... .......... .......... 88% 1.13M 0s
   500K .......... .......... .......... .......... .......... 97%  702K 0s
   550K .......... ..                                         100% 3.13M=0.7s

2011-02-05 11:15:11 (777 KB/s) - `Red_Apple.jpg' saved [576216/576216]

Here we use two important tools: ssh and wget. Most output is from wget — but it is output of wget instance launched on the remote machine; the file is saved in user's home directory on remote-host.

1
  • +1, probably the fastest way to do it and easily scriptable.
    – hyperslug
    Feb 5, 2011 at 14:42
1

now, this would depend if you're using shared hosting, or something with a lot more freedom. If its the former, it'd like have to be an ugly cludge.

If you had a VPS or some other hosting with effectively a system to yourself, you could set up what you need - say a torrent client, something like torrentflux if you wanted full access and/or either the aformentioned ssh/cli client method (though, if bored enough, a combination of dropbox to upload the links to the server, combined with a clever cron script would be a wonderfully abusive way of telling a system what files to open/download with what).

You might even be able to periodically compress your download into chunks for upload to save even more bandwith.

1

Create a folder called "downloads" in destination server. Save this code into a .php file and run in destination server:

<html>
<form method="post">
<input name="url" size="50" />
<input name="submit" type="submit" />
</form>
<?php

// maximum execution time in seconds
set_time_limit (24 * 60 * 60);

if (!isset($_POST['submit'])) die();


// folder to save downloaded files to. must end with slash
$destination_folder = 'downloads/';

$url = $_POST['url'];
$newfname = $destination_folder . 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);
}

?>
</html> 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .