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
  • 18,244
  • 13
  • 59
  • 81
Sourav
  • 17,065
  • 35
  • 101
  • 159
  • 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 – mohdajami 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,421,763
  • 867
  • 9,128
  • 9,194
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
  • 93,659
  • 19
  • 148
  • 186
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
  • 95,432
  • 20
  • 163
  • 226