PROXY ACCESS

PROXY ACCESS

Postby Silvio » Tue Feb 12, 2008 11:00 am

I must use ftp of Emg to download a file
it run ok I have only problems with the upload

Wich command I must use to go out from proxy and then use ftp of Enrico ?

thanks in advance
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: PROXY ACCESS

Postby Enrico Maria Giordano » Tue Feb 12, 2008 11:06 am

Try to specify the proxy name in the call to InternetOpen():

Code: Select all  Expand view  RUN
hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_PROXY, "your proxy name", 0, 0 )


Please note also the use of INTERNET_OPEN_TYPE_PROXY.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8716
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Silvio » Tue Feb 12, 2008 11:08 am

ok but I must insert also mycoduser and mypass for this proxy , and the port number ( my port is 8080)

where i set all this ?
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Postby Enrico Maria Giordano » Tue Feb 12, 2008 11:12 am

I don't think you have to provide them. Anyway, FTP functions doesn't seem to require userid and password of the proxy.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8716
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Silvio » Tue Feb 12, 2008 12:21 pm

EMG look this ... I add a dialog to your sample :

Code: Select all  Expand view  RUN

#include "Fivewin.ch"


//
// File attributes
//

#define FILE_ATTRIBUTE_READONLY  1
#define FILE_ATTRIBUTE_HIDDEN    2
#define FILE_ATTRIBUTE_SYSTEM    4
#define FILE_ATTRIBUTE_DIRECTORY 16
#define FILE_ATTRIBUTE_ARCHIVE   32
#define FILE_ATTRIBUTE_NORMAL    128
#define FILE_ATTRIBUTE_TEMPORARY 256


//
// access types for InternetOpen()
//

#define INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
#define INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
#define INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS


//
// manifests
//

#define INTERNET_INVALID_PORT_NUMBER    0           // use the protocol-specific default

#define INTERNET_DEFAULT_FTP_PORT       21          // default for FTP servers
#define INTERNET_DEFAULT_GOPHER_PORT    70          //    "     " gopher "
#define INTERNET_DEFAULT_HTTP_PORT      80          //    "     " HTTP   "
#define INTERNET_DEFAULT_HTTPS_PORT     443         //    "     " HTTPS  "
#define INTERNET_DEFAULT_SOCKS_PORT     1080        // default for SOCKS firewall servers.


//
// service types for InternetConnect()
//

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


//
// flags for FTP
//

#define INTERNET_FLAG_TRANSFER_ASCII  1
#define INTERNET_FLAG_TRANSFER_BINARY 2


//
// file access types
//

#define GENERIC_READ  2147483648
#define GENERIC_WRITE 1073741824



FUNCTION MAIN()

    LOCAL oDlg, oPrg


    // DATA

    Local myftpaddress :=space(40)
    Local myuserid     :=space(30)
    Local mypassword   :=space(20)
    LOCAL mydirfrom    :="/emagsoftware.it/test/atest.prg"
    Local MyFIle       :="emag.mdb"

    // if use proxy
    Local oChkProxy, lValue:=.f.
    Local MyProxy      :=Space(20)
    Local MyuserProxy  :=Space(20)
    Local MyProxyPAss :=space(20)
    Local MyPortProxy  :=0


    DEFINE DIALOG oDlg FROM 2,10 TO 24,90  ;
    TITLE "FTP TEST  of EMG"


   @ 0.8,    2 SAY "Ftp Address: "    OF oDlg
   @ 1,    6 GET myftpaddress         OF oDlg  SIZE 100, 10

   @ 1.8,  2 SAY "My userid : "        OF oDlg
   @ 2,  6 GET myuserid               OF oDlg  SIZE 100, 10

   @ 2.5,  2 SAY "My password :  "       OF oDlg
   @ 3,  6 GET mypassword             OF oDlg  SIZE 100, 10

   @ 3.4,  2 SAY "My dir From  : "       OF oDlg
   @ 4,  6 GET mydirfrom              OF oDlg  SIZE 100, 10

   @ 4.8,  2 SAY "My File : "           OF oDlg
   @ 5.6,  6 GET myfile               OF oDlg  SIZE 100, 10


   // Proxy Use

   @ 0.2, 22 GROUP oGrp TO 6, 45 PROMPT "Proxy use"

   @ 0.8,  26 SAY "Proxy Address: "    OF oDlg
   @ 1,    26 GET myProxy              OF oDlg  SIZE 100, 10  WHEN   lValue
   @ 1.8,  26 SAY "My ProxyID : "      OF oDlg
   @ 2,    26 GET MyuserProxy          OF oDlg  SIZE 100, 10  WHEN   lValue
   @ 2.5,  26 SAY "My Proxy Pass :  "  OF oDlg
   @ 3,    26 GET MyProxyPAss          OF oDlg  SIZE 100, 10  WHEN   lValue
   @ 3.4,  26 SAY "My Proxy Port  : "  OF oDlg
   @ 4,    26 GET MyPortProxy          OF oDlg  SIZE 100, 10   WHEN   lValue
   @ 4.8,  26 CHECKBOX oChkProxy VAR lValue PROMPT "&Proxy use" SIZE 100, 20 OF oDlg


   // Tprogress
    @ 7.4, 2 PROGRESS oPrg;
           SIZE 250, 15


    @ 7.5, 2 BUTTON "FTP download";
           ACTION DOWNLOAD( oPrg )

    @ 7.5, 21 BUTTON "EXIT";
           ACTION oDlg:End()


    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


STATIC FUNCTION DOWNLOAD( oPrg )

    LOCAL hInternet, hConnect, hSource, hDest, nRead

    LOCAL cData := SPACE( 1024 )

    LOCAL nPos := 0

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

    hConnect = INTERNETCONNECT( hInternet, myftpaddress, INTERNET_INVALID_PORT_NUMBER, myuserid, mypassword, INTERNET_SERVICE_FTP, 0, 0 )

    hSource = FTPOPENFILE( hConnect, mydirfrom, GENERIC_READ, 0, 0 )

    oPrg:SetPos( 0 )

    oPrg:SetRange( 0, FTPGETFILESIZE( hSource ) )

    hDest = FCREATE( MyFIle)

    WHILE .T.
        nRead = INTERNETREADFILE( hSource, @cData )

        IF nRead = -1
            ? "Download error"
            EXIT
        ENDIF

        IF nRead = 0
            ? "Download OK"
            EXIT
        ENDIF

        FWRITE( hDest, cData, nRead )

        nPos += LEN( cData )

        oPrg:SetPos( nPos )
    ENDDO

    FCLOSE( hDest )

    INTERNETCLOSEHANDLE( hSource )

    INTERNETCLOSEHANDLE( hConnect )

    INTERNETCLOSEHANDLE( hInternet )

    RETURN NIL


#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( FTPOPENFILE )
{
    hb_retnl( ( LONG ) FtpOpenFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parnl( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) ) );
}


HB_FUNC( FTPGETFILESIZE )
{
    DWORD nFileSizeHigh;

    hb_retnl( ( LONG ) FtpGetFileSize( ( HINTERNET ) hb_parnl( 1 ), &nFileSizeHigh ) );
}


HB_FUNC( INTERNETREADFILE )
{
    DWORD nBytesRead;

    BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );

    if ( !lSuccess )
        hb_retnl( -1 );
    else
        hb_retnl( nBytesRead );
}

#pragma ENDDUM
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 62 guests