Page 1 of 1

URL Download to File

Posted: Sat Jun 17, 2017 9:33 am
by bpd2000
Working example of URLdownloadto file
It finished after expert help from KDJ

Code: Select all

/*
From bpd2000
Expert help from KDJ
*/


#include "hmg.ch"

function Main()

   local Down_Result, cURL := "http://www.hmgforum.com/download/file.php?id=8044"

   Down_Result := DOWNLOADFILE( cURL, HB_CWD() + "Down_file.ZIP" )
                         //file will be downloaded in current directory
  
  If Down_Result = 0 
        MsgStop ( "File " + cURL + hb_osnewline() + "has been downloaded!")
    Else 
        MsgStop ("File not found!")
  EndIf 


RETURN NIL

#pragma BEGINDUMP

#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"

#include <Windows.h>
#include <urlmon.h>
#include "hbapi.h"

HB_FUNC( DOWNLOADFILE )
{
   HRESULT hr;
        
   hr = URLDownloadToFileW( NULL, HMG_parc( 1 ), HMG_parc( 2 ), 0, NULL );
  
   hb_retnl( hr ) ;
}

#pragma ENDDUMP


Re: URL Download to File

Posted: Wed Jun 28, 2017 2:48 pm
by Rathinagiri
Thank you!. With this I have automated to download 1300+ files at a stretch! :)