0

I want to download some files programatically from a remote server.

If you can write the code-snippet in VB, VB.NET, Java, or PHP I can try to solve the rest by myself.

Sample file address:

  • www.example.com/file1.pdf
  • www.example.com/file2.pdf
  • www.example.com/file%20n-1.pdf

It will be helpful if you give solutions to this problem in PHP so I can test in WAMP.

Chris Smith
  • 17,474
  • 12
  • 57
  • 78
Sourav
  • 16,318
  • 34
  • 98
  • 153
  • 1
    [PHP snippet](http://stackoverflow.com/questions/728458/best-way-to-download-a-file-in-php) – Searock Dec 14 '11 at 07:28
  • [VB 6.0 Snippet](http://stackoverflow.com/questions/1976152/download-file-vb6) – Searock Dec 14 '11 at 07:45
  • 1
    Adding some source code, or what you have tried would be better. Check StackOverflow FAQ http://stackoverflow.com/faq#questions – medopal Dec 14 '11 at 07:55
  • possible duplicate of [How to use HttpWebRequest to download file](http://stackoverflow.com/questions/6778055/how-to-use-httpwebrequest-to-download-file) – George Stocker Dec 14 '11 at 16:22

3 Answers3

3

In VB.NET, WebClient makes this trivial:

new WebClient().DownloadFile(url, filename)
Jon Skeet
  • 1,335,956
  • 823
  • 8,931
  • 9,049
1

In Java, you may use java.net.URL and java.net.URLConnection class methods.

SO Thread - How to download and save a file from internet using Java.

Community
  • 1
  • 1
KV Prajapati
  • 92,042
  • 19
  • 143
  • 183
0

PHP example

<?php
$files = array('file1.pdf', 'file2.pdf', 'filen.pdf');

$remoteBase = 'http://www.site.com/';
$localBase = 'downloads/';

foreach( $files as $f ) {
    $fp = fopen($remoteBase.$f, 'rb');
    if ( !$fp ) {
        echo 'error, ', $f, "\n";
    }
    else {
        file_put_contents($localBase.$f, $fp);
        fclose($fp);
    }
}
VolkerK
  • 93,904
  • 19
  • 160
  • 225