Function to download a defined file from a homepage ?

User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

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

Post by karinha »

João Santos - São Paulo - Brasil
russimicro
Posts: 179
Joined: Sun Jan 31, 2010 3:30 pm
Location: Bucaramanga - Colombia

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

Post by russimicro »

Code: Select all

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


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


 
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

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

Post by ukoenig »

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
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

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

Post by Silvio.Falconi »

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 ?
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

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

Post by ukoenig »

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: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

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

Post by ukoenig »

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
MaxP
Posts: 85
Joined: Thu Jul 12, 2007 2:02 pm
Contact:

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

Post by MaxP »

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

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

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

Post by Baxajaun »

Hello Massimo,

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

Best regards,
User avatar
MaxP
Posts: 85
Joined: Thu Jul 12, 2007 2:02 pm
Contact:

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

Post by MaxP »

I use NMAKE with

file MAKEFILE

Code: Select all

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

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
Baxajaun
Posts: 853
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

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

Post by Baxajaun »

Hi Massimo,

my errors with your code:

Code: Select all

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
MaxP
Posts: 85
Joined: Thu Jul 12, 2007 2:02 pm
Contact:

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

Post by MaxP »

Try with these changes

Code: Select all

    #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
Baxajaun
Posts: 853
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

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

Post by Baxajaun »

Hi Massimo,

thanks for your help, but the same result.

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

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

Post by MaxP »

Another test

Code: Select all

#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
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

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

Post by Antonio Linares »

Code: Select all

#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
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

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

Post by Otto »

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

********************************************************************
Post Reply