Page 1 of 2

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! :)

Re: URL Download to File

Posted: Wed Mar 07, 2018 12:38 pm
by serge_girard
Hello,

How to compile in HMG ?

Serge

Re: URL Download to File

Posted: Wed Mar 07, 2018 1:08 pm
by bpd2000
serge_girard wrote: Wed Mar 07, 2018 12:38 pm Hello,

How to compile in HMG ?

Serge
.hbp file content
//---------
#harbour options:
-a
-m
-n
-v
-w3

#hbmk2 options:
-lurlmon


#sources:
Url_Down_Demo.prg
//---------
Are you facing any error ?

Re: URL Download to File

Posted: Wed Mar 07, 2018 1:57 pm
by serge_girard
Hello,

I try to integrate in existing application. I get 'undefined reference to URLDownloadToF....'
My HBP file contains only PRG's and with -a -m... lots of errors

Serge

Re: URL Download to File

Posted: Wed Mar 07, 2018 3:09 pm
by serge_girard
BPD,

OK now ! Thanks !

Serge

Re: URL Download to File

Posted: Wed Mar 07, 2018 6:47 pm
by apais
PMFJI but..

what was it ?

Re: URL Download to File

Posted: Wed Mar 07, 2018 8:27 pm
by serge_girard
Don't know, just erased #harbour options !

Serge

Re: URL Download to File

Posted: Thu Mar 08, 2018 6:13 am
by hmgchang
Great.... But can i use it to download my hmgforum unread( 6905) and save each topics to seperate folder ?

TIA
Chang

Re: URL Download to File

Posted: Fri Mar 09, 2018 6:06 pm
by andyglezl
Gracias bpd200 y KDJ !!!

Y tambien a todos los involucrados con sus comentario y dudas
porque de ahí resulta que se aclare, se aprenda, se modifique para cada necesidad...
-----------------------------------------------------------------------------------------------------------
Thanks bpd200 and KDJ !!!

And also to all those involved with their comments and doubts
because it results in clarification, learning, modification for every need ...


Aquí el mismo ejemplo modificado
------------------------------------------
Here the same modified example


Code: Select all

/*
From bpd2000
Expert help from KDJ
*/


#include "hmg.ch"

function Main()

   local Down_Result, cURL
   FOR i1 = 1 to 10	// Download All Files post from 1 to 10
      cNumPost := ALLTRIM( STR( i1, 6 ) )
      cURL := "http://www.hmgforum.com/download/file.php?id="+cNumPost
      Down_Result := DOWNLOADFILE( cURL, HB_CWD() + "HMGPOST_"+cNumPost+".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 
   NEXT

RETURN NIL