Page 1 of 1

FTP with Harbour / MSVC / FWH issues

Posted: Tue Jun 19, 2018 11:56 pm
by TimStone
I am running a program built with xHarbour / FWH that must do FTP processes. It works perfectly. I am using the .dll WININET and calling the functions:
INTERNETOPEN
INETCLOSEHANDLE
FTPGETFILE
FTPPUTFILE
INTERNETCONNECT

However, when I build using Harbour / MSVC / FWH, it appears to not recognize the WININET.dll because it gives me unidentified externals when trying to do run a successful build

These are all redefined as follows:

Code: Select all


DLL32 FUNCTION InternetOpen( cAgent AS LPSTR, nAccessType AS DWORD, cProxyName AS LPSTR, cProxyBypass AS LPSTR, nFlags ;
    AS DWORD ) AS LONG PASCAL FROM "InternetOpenA" LIB iDLL

DLL32 FUNCTION INETCLOSEHANDLE( hInternet AS LONG ) AS BOOL;
    PASCAL FROM "InternetCloseHandle" LIB iDLL

DLL32 FUNCTION FTPGETFILE( hConnect AS LONG, cRemoteFile AS LPSTR, cNewFile AS LPSTR, nFailIfExists AS LONG, ;
    nFlagsAndAttribs AS DWORD, nFlags AS DWORD, @nContext AS PTR ) AS BOOL PASCAL FROM "FtpGetFileA" LIB iDLL

DLL32 FUNCTION FtpPutFile( hFTP AS LONG, cFileName AS LPSTR, cDestFile AS LPSTR,;
    n1 AS LONG, n2 AS LONG ) AS BOOL PASCAL ;
    FROM "FtpPutFileA" LIB iDLL

DLL32 FUNCTION InternetConnect( hSession AS LONG, cHost AS LPSTR, nPort AS LONG,;
    cUserName AS LPSTR, cPassword AS LPSTR, n4 AS LONG, n5 AS LONG,;
    n6 AS LONG ) AS LONG PASCAL ;
    FROM "InternetConnectA" LIB iDLL
 
iDLL is defined:
PRIVATE iDLL := LoadLibrary( "wininet.dll" )

As I said, this code is fine with xHarbour, but not Harbour. I've tried other approaches but all are problematic. Any ideas on this one ?

Re: FTP with Harbour / MSVC / FWH issues

Posted: Thu Jun 21, 2018 11:44 am
by Enrico Maria Giordano
Please, check your message and fix it. :-)

EMG

Re: FTP with Harbour / MSVC / FWH issues

Posted: Thu Jun 21, 2018 6:21 pm
by TimStone
Took out the spurious part ..l

Re: FTP with Harbour / MSVC / FWH issues

Posted: Thu Jun 21, 2018 6:49 pm
by Enrico Maria Giordano
The following sample compiles and links fine here (of course it doesn't run):

Code: Select all

#include "Fivewin.ch"


STATIC iDLL


FUNCTION MAIN()

    INTERNETOPEN()
    INTERNETCLOSEHANDLE()
    FTPGETFILE()
    FTPPUTFILE()
    INTERNETCONNECT()

    RETURN NIL


DLL32 FUNCTION InternetOpen( cAgent AS LPSTR, nAccessType AS DWORD, cProxyName AS LPSTR, cProxyBypass AS LPSTR, nFlags ;
    AS DWORD ) AS LONG PASCAL FROM "InternetOpenA" LIB iDLL

DLL32 FUNCTION INETCLOSEHANDLE( hInternet AS LONG ) AS BOOL;
    PASCAL FROM "InternetCloseHandle" LIB iDLL

DLL32 FUNCTION FTPGETFILE( hConnect AS LONG, cRemoteFile AS LPSTR, cNewFile AS LPSTR, nFailIfExists AS LONG, ;
    nFlagsAndAttribs AS DWORD, nFlags AS DWORD, @nContext AS PTR ) AS BOOL PASCAL FROM "FtpGetFileA" LIB iDLL

DLL32 FUNCTION FtpPutFile( hFTP AS LONG, cFileName AS LPSTR, cDestFile AS LPSTR,;
    n1 AS LONG, n2 AS LONG ) AS BOOL PASCAL ;
    FROM "FtpPutFileA" LIB iDLL

DLL32 FUNCTION InternetConnect( hSession AS LONG, cHost AS LPSTR, nPort AS LONG,;
    cUserName AS LPSTR, cPassword AS LPSTR, n4 AS LONG, n5 AS LONG,;
    n6 AS LONG ) AS LONG PASCAL ;
    FROM "InternetConnectA" LIB iDLL
EMG

Re: FTP with Harbour / MSVC / FWH issues

Posted: Thu Jun 21, 2018 11:29 pm
by TimStone
Yes, it compiles and links fine ... but then when I run it, it can't find the function. Therein lies the problem.

Re: FTP with Harbour / MSVC / FWH issues

Posted: Fri Jun 22, 2018 8:03 am
by Enrico Maria Giordano
Please, provide a reduced and self-contained sample of the problem.

EMG

Re: FTP with Harbour / MSVC / FWH issues

Posted: Fri Jun 22, 2018 9:17 pm
by russimicro
xharbour.com + fivewin

Code: Select all



// 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


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

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

    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 sinEspera == NIL

       IF lOk
          msgwait(hb_oemtoansi("La transferencia v¡a FTP, fue exitosa"),"Aviso informativo",5 )
       ELSE
          msgwait(hb_oemtoansi("La transferencia v¡a FTP, fue fallida"),"Aviso informativo",5 )
       ENDIF
    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


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


 

Re: FTP with Harbour / MSVC / FWH issues

Posted: Mon Jun 25, 2018 5:23 pm
by TimStone
I have it functioning with xHabour. I want to use Harbour + MSVC + FWH.

Re: FTP with Harbour / MSVC / FWH issues

Posted: Wed Jun 27, 2018 8:22 am
by ShumingWang
Another , how use ftp over TLS ?

hLib = LOADLIBRARY( "wininet.dll" )

hInternet := INETOPEN( "Anystring", 1, 0, 0, 0 )

hConnect := INETCONNECT( hInternet, "www.xtech.com.cn",21, "xxx@xtech.com.cn", "erp6.5", 1, 0,0 )

if !EMPTY( hInternet ).and.!EMPTY( hConnect )
msgmeter({|ometer,otext,odlg,lend|download002(ometer,otext,odlg,@lend,hConnect)},"正在下载,可能需要几分钟...","下载提示")
msginfo("已经升级完毕","提示")
else
msginfo("网络不通,下载失败","提示")
// remote, local file
end
INETCLOSEHANDLE( hConnect )
INETCLOSEHANDLE( hInternet )
FREELIBRARY( hLib )

return nil

FUNCTION download002(ometer,otext,odlg,lend,hConnect)
local n1:=0

ometer:SetTotal(3)
ometer:set(++n1)
FTPGETFILE( hConnect, "xerp.exe", "xerp.exe", 0,32, 0, 0 )
ometer:set(++n1)
FTPGETFILE( hConnect, "xerp.dll", "xerp.dll", 0,32, 0, 0 )
ometer:set(++n1)
return .t.

DLL32 FUNCTION INETOPEN( cAgent AS LPSTR, nAccessType AS DWORD, cProxyName AS LPSTR, cProxyBypass AS LPSTR, nFlags AS DWORD ) AS LONG;
PASCAL FROM "InternetOpenA" LIB hLib

DLL32 FUNCTION INETCLOSEHANDLE( hInternet AS LONG ) AS BOOL;
PASCAL FROM "InternetCloseHandle" LIB hLib

DLL32 FUNCTION INETCONNECT( hInternet AS LONG, cServerName AS LPSTR, nServerPort AS LONG, cUserName AS LPSTR, cPassword AS LPSTR, nService AS DWORD, nFlags AS DWORD, @nContext AS PTR ) AS LONG;
PASCAL FROM "InternetConnectA" LIB hLib

DLL32 FUNCTION FTPGETFILE( hConnect AS LONG, cRemoteFile AS LPSTR, cNewFile AS LPSTR, nFailIfExists AS LONG, nFlagsAndAttribs AS DWORD, nFlags AS DWORD, @nContext AS PTR ) AS BOOL;
PASCAL FROM "FtpGetFileA" LIB hLib

DLL32 FUNCTION FTPPUTFILE( hConnect AS LONG, cLocalFile AS LPSTR, cNewRemoteFile AS LPSTR, nFlags AS DWORD, @nContext AS PTR ) AS BOOL;
PASCAL FROM "FtpPutFileA" LIB hLib
Thanks !
Shuming Wang