Function to download a defined file from a homepage ?

Re: Function to download a defined file from a homepage ?

Postby karinha » Fri Apr 22, 2016 7:01 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7315
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Function to download a defined file from a homepage ?

Postby russimicro » Fri Apr 22, 2016 7:12 pm

Code: Select all  Expand view

via ftp : ok perfect ,,,

// Wininet constants

#define INTERNET_OPEN_TYPE_PRECONFIG                    0
#define INTERNET_OPEN_TYPE_DIRECT                       1
#define INTERNET_OPEN_TYPE_PROXY                        3
#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4

#define INTERNET_INVALID_PORT_NUMBER    0
#define INTERNET_DEFAULT_FTP_PORT       21
#define INTERNET_DEFAULT_GOPHER_PORT    70
#define INTERNET_DEFAULT_HTTP_PORT      80
#define INTERNET_DEFAULT_HTTPS_PORT     443
#define INTERNET_DEFAULT_SOCKS_PORT     1080

#define INTERNET_SERVICE_FTP     1
#define INTERNET_SERVICE_GOPHER  2
#define INTERNET_SERVICE_HTTP    3

#define INTERNET_FLAG_TRANSFER_ASCII  1
#define INTERNET_FLAG_TRANSFER_BINARY 2
#define MODE  2
#define INTERNET_FLAG_ACTIVE  0
#define INTERNET_FLAG_PASSIVE 134217728
#define FILE_ATTRIBUTE_ARCHIVE 128

// FTPGETFILE( hConnect, cRemotePath + "/" + alltrim( cFileName ),"c:\temp\autoexec.bat", 0, FILE_ATTRIBUTE_ARCHIVE, 0, 0 )

//**********************************************************************

FUNCTION FTPWRITEFILE( cServerName, cLocalPath, cRemotePath, cUserName, cPassword, cFileName )

    LOCAL hInternet, hConnect
    LOCAL lOk

    IF !FILE(cLocalPath + alltrim(cFileName))
       MYMEN("Error. Archivo no existe : "+cLocalPath + alltrim(cFileName))
       RETURN .F.
    ENDIF

    hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )

    hConnect = INTERNETCONNECT( hInternet, cServerName, INTERNET_DEFAULT_FTP_PORT, cUserName, cPassword, INTERNET_SERVICE_FTP, MODE, 0 )

    lOk = FTPPUTFILE( hConnect, cLocalPath +  alltrim(cFileName), cRemotePath +  alltrim( cFileName ), 0, 0 )

    IF lOk
       msgwait(hb_oemtoansi("La transferencia v¡a FTP, fue exitosa"),"Aviso informativo",10 )
    ELSE
       msgwait(hb_oemtoansi("La transferencia v¡a FTP, fue fallida"),"Aviso informativo",10 )
    ENDIF

    INTERNETCLOSEHANDLE( hConnect )
    INTERNETCLOSEHANDLE( hInternet )

    RETURN lOk

//***************************************************************

#pragma BEGINDUMP

   #include "windows.h"
   #include "wininet.h"
   #include "hbapi.h"

   HB_FUNC( INTERNETOPEN )
   {
       hb_retnl( ( LONG ) InternetOpen( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ), hb_parnl( 5 ) ) );
   }
   HB_FUNC( INTERNETCLOSEHANDLE )
   {
       hb_retl( InternetCloseHandle( ( HINTERNET ) hb_parnl( 1 ) ) );
   }
   HB_FUNC( INTERNETCONNECT )
   {
       hb_retnl( ( LONG ) InternetConnect( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), ( INTERNET_PORT ) hb_parnl( 3 ), hb_parc( 4 ), hb_parc( 5 ), hb_parnl( 6 ), hb_parnl( 7 ), hb_parnl( 8 ) ) );
   }
   HB_FUNC( FTPPUTFILE )
   {
       hb_retl( FtpPutFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parc( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) ) );
   }
   HB_FUNC( FTPGETFILE )
   {
       hb_retl( FtpGetFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parc( 3 ), hb_parl( 4 ), hb_parnl( 5 ), hb_parnl( 6 ), hb_parnl( 7 ) ) );
   }

#pragma ENDDUMP


//*******************************************************


 
russimicro
 
Posts: 229
Joined: Sun Jan 31, 2010 3:30 pm
Location: Bucaramanga - Colombia

Re: Function to download a defined file from a homepage ?

Postby ukoenig » Fri Apr 22, 2016 8:01 pm

Thank You very much for all the help.

I will carry on with testing.

with testing the FWH sample from < samples/GalleryIcopyfil/Icopyfil.prg >
I reached this point : serverconnection, but the copyprocess doesn't start.

I listed the homepage-directory :

aFiles = oFTP:Directory( "*.*" ) // , "D" )
AEval( aFiles, { | aFile | MsgInfo( aFile[ 1 ], aFile[ 3 ] ) } )

results :
------------------
.
..
Firma
Testfile.zip // a testfile
Service // subdirectory
Software // Subdirectory
_we_info // file
index.html
// file
-------------------

my downloadfiles are inside the subdirectory < Software/DOWNLOADS >
that can be the reason that no download is executed

Image

regards
Uwe :roll:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Function to download a defined file from a homepage ?

Postby Silvio.Falconi » Sat Apr 23, 2016 3:12 pm

sorry Uwe I saw now your message

the tupdate class here run ok perhaps there is a protection on your website ?
do you have CLASS TFTP ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6834
Joined: Thu Oct 18, 2012 7:17 pm

Re: Function to download a defined file from a homepage ?

Postby ukoenig » Sat Apr 23, 2016 4:19 pm

Silvio,

NO nothing special or protection
From inside the Forum there is no problem to download a file.
There is nothing else I need.
With the FWH-sample ( defined above ) I can open the homepage and check the directory.
Maybe I have to check the solution from Stephan again

regards
Uwe :(
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Function to download a defined file from a homepage ?

Postby ukoenig » Sat Apr 23, 2016 10:30 pm

Silvio,

the solution from Stephan
after some more tests, I found the problem and got it working

there is a directory problem

my files are stored inside a subdirectory of < Software >
< Software > is one of the subdirectorys of < root >
inside < Software > a subdirectory < DOWNLOADS > is defined for downloads
it only workes storing files in subdirectory < Software > ( 1. level )

LOCAL cFtpDir := "Software" // a subdirectory of ROOT -> works !!!
using
LOCAL cFtpDir := "Software/DOWNLOADS"
doesn' work :(

-------------------------
. // Root
..
Software // Subdirectory
Software/DOWNLOADS // Subdirectory of download-files
--------------------------

that means I have to save all downloadfiles in < Software > or create a new directory.

I think with :
::oFtp:SetCurrentDirectory( ??????? )
it is possible to move to any subdirectory ?

regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Function to download a defined file from a homepage ?

Postby MaxP » Tue Apr 26, 2016 2:36 pm

I use the borland compiler and I include
c:\borland\bcc55\lib\psdk\urlmon.lib

regards
Massimo
User avatar
MaxP
 
Posts: 84
Joined: Thu Jul 12, 2007 2:02 pm

Re: Function to download a defined file from a homepage ?

Postby Baxajaun » Tue Apr 26, 2016 3:13 pm

Hello Massimo,

could you publish your make or batch file to compile your simple ?

Best regards,
User avatar
Baxajaun
 
Posts: 962
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Re: Function to download a defined file from a homepage ?

Postby MaxP » Tue Apr 26, 2016 3:30 pm

I use NMAKE with

file MAKEFILE
Code: Select all  Expand view

TEST.EXE :     TEST.obj
        C:\BORLAND\BCC55\bin\ilink32 -Gn -aa -Tpe -s -LC:\BORLAND\BCC55\lib @TEST.bc

TEST.c :   TEST.prg
        C:\HARBOUR\BIN\HARBOUR TEST /n /w /p /IC:\HARBOUR\INCLUDE;C:\FWH\INCLUDE /DNORMAL

TEST.obj :   TEST.c
        C:\BORLAND\BCC55\BIN\BCC32 -M -c /IC:\HARBOUR\INCLUDE;C:\BORLAND\BCC55\INCLUDE;C:\FWH\INCLUDE TEST.c
 


and file TEST.BC

Code: Select all  Expand view

C:\BORLAND\BCC55\lib\c0w32.obj +
TEST.obj, +
TEST.EXE, +
TEST.MAP, +
C:\FWH\lib\FiveH.lib +
C:\FWH\lib\FiveHC.lib +
c:\harbour\lib\rtl.lib +
c:\harbour\lib\vm.lib +
c:\harbour\lib\gtgui.lib +
c:\harbour\lib\lang.lib +
c:\harbour\lib\macro.lib +
c:\harbour\lib\rdd.lib +
c:\harbour\lib\dbfntx.lib +
c:\harbour\lib\dbfcdx.lib +
c:\harbour\lib\dbffpt.lib +
c:\harbour\lib\hbsix.lib +
c:\harbour\lib\debug.lib +
c:\harbour\lib\common.lib +
c:\harbour\lib\codepage.lib +
c:\borland\bcc55\lib\cw32.lib +
c:\borland\bcc55\lib\import32.lib +
c:\borland\bcc55\lib\psdk\odbc32.lib +
c:\borland\bcc55\lib\psdk\nddeapi.lib +
c:\borland\bcc55\lib\psdk\iphlpapi.lib +
c:\borland\bcc55\lib\psdk\rasapi32.lib +
c:\borland\bcc55\lib\psdk\urlmon.lib +
c:\borland\bcc55\lib\inet.lib
 


regards
Massimo
User avatar
MaxP
 
Posts: 84
Joined: Thu Jul 12, 2007 2:02 pm

Re: Function to download a defined file from a homepage ?

Postby Baxajaun » Thu Apr 28, 2016 1:09 pm

Hi Massimo,

my errors with your code:

Code: Select all  Expand view
MAKE Version 5.2  Copyright (c) 1987, 2000 Borland
        echo -c -tWM -D__HARBOUR__ -DHB_API_MACROS > tmp
        echo -Ic:\develop\harbour\include;c:\develop\fwh\include >> tmp
        c:\develop\borland\bcc55\bin\bcc32 -oobj\TestDownload @tmp TestDownload.
c
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
TestDownload.c:
Error E2238 c:\develop\harbour\include\clipdefs.h 80: Multiple declaration for ' WORD'
Error E2344 c:\Develop\Borland\Bcc55\include\windef.h 145: Earlier declaration of 'WORD'
Error E2238 c:\develop\harbour\include\clipdefs.h 82: Multiple declaration for ' PWORD'
Error E2344 c:\Develop\Borland\Bcc55\include\windef.h 154: Earlier declaration of 'PWORD'
Error E2238 c:\develop\harbour\include\clipdefs.h 102: Multiple declaration for 'BOOL'
Error E2344 c:\Develop\Borland\Bcc55\include\windef.h 143: Earlier declaration of 'BOOL'
Error E2238 c:\develop\harbour\include\clipdefs.h 105: Multiple declaration for 'PBOOL'
Error E2344 c:\Develop\Borland\Bcc55\include\windef.h 148: Earlier declaration of 'PBOOL'
Error E2238 c:\develop\harbour\include\clipdefs.h 114: Multiple declaration for 'HANDLE'
Error E2344 c:\Develop\Borland\Bcc55\include\winnt.h 283: Earlier declaration of  'HANDLE'
*** 10 errors in Compile ***


Thanks in advance !

Regards
User avatar
Baxajaun
 
Posts: 962
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Re: Function to download a defined file from a homepage ?

Postby MaxP » Thu Apr 28, 2016 2:48 pm

Try with these changes

Code: Select all  Expand view

    #include "fivewin.ch"

    function Main()
            LOCAL   nRet
           
            nRet := DOWNLOADFILE( "http://www.yoursite.it/index.html", "C:\index.html" )
           
            MsgStop( nRet )
    RETURN NIL


    #pragma BEGINDUMP

    #include <WinTen.h>
    #include <Windows.h>
    #include <ClipApi.h>
    #include <urlmon.h>

    HB_FUNC( DOWNLOADFILE )

    {
            unsigned long   lRet ;
           
            lRet = URLDownloadToFile( NULL, _parc( 1 ), _parc( 2 ), 0, NULL ) ;
           
            _retnl( lRet ) ;
    }

    #pragma ENDDUMP
 


best regards
Massimo
User avatar
MaxP
 
Posts: 84
Joined: Thu Jul 12, 2007 2:02 pm

Re: Function to download a defined file from a homepage ?

Postby Baxajaun » Fri Apr 29, 2016 4:45 am

Hi Massimo,

thanks for your help, but the same result.

Regards
User avatar
Baxajaun
 
Posts: 962
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Re: Function to download a defined file from a homepage ?

Postby MaxP » Fri Apr 29, 2016 7:38 am

Another test

Code: Select all  Expand view

#include "fivewin.ch"

    function Main()
            LOCAL   nRet
           
            nRet := DOWNLOADFILE( "http://www.yoursite.it/index.html", "C:\index.html" )
           
            MsgStop( nRet )
    RETURN NIL


    #pragma BEGINDUMP

    #define _CLIPDEFS_H

    #include <WinTen.h>
    #include <Windows.h>
    #include <ClipApi.h>
    #include <urlmon.h>

    HB_FUNC( DOWNLOADFILE )

    {
            unsigned long   lRet ;
           
            lRet = URLDownloadToFile( NULL, _parc( 1 ), _parc( 2 ), 0, NULL ) ;
           
            _retnl( lRet ) ;
    }

    #pragma ENDDUMP
 


Regards
User avatar
MaxP
 
Posts: 84
Joined: Thu Jul 12, 2007 2:02 pm

Re: Function to download a defined file from a homepage ?

Postby Antonio Linares » Fri Apr 29, 2016 9:02 am

Code: Select all  Expand view
#include "fivewin.ch"

    function Main()
            LOCAL   nRet
           
            nRet := DOWNLOADFILE( "http://www.yoursite.it/index.html", "C:\index.html" )
           
            MsgStop( nRet )
    RETURN NIL


    #pragma BEGINDUMP

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

    HB_FUNC( DOWNLOADFILE )

    {
            HRESULT hr;
           
            hr = URLDownloadToFile( NULL, hb_parc( 1 ), hb_parc( 2 ), 0, NULL ) ;
           
            hb_retnl( hr ) ;
    }

    #pragma ENDDUMP
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Function to download a defined file from a homepage ?

Postby Otto » Thu May 12, 2016 5:25 pm

Dear Antonio,
where do we find:
URLDownloadToFile

Is this only for Harbour.

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6045
Joined: Fri Oct 07, 2005 7:07 pm

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 29 guests

cron