FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Conectar a un SFTP con CURL usando xHarbour ...
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Conectar a un SFTP con CURL usando xHarbour ...
Posted: Tue Jul 18, 2023 10:10 PM

Estimados Saludos

Alguien lo probo con xHarbour ?? , si se que Harbour seria ideal, pero tengo mucho que modificar y por ahora no tenemos tiempo, Yo he compilado y todo, pero al ejecutar me da un error :

Error irrecuperable 9011

hb_xfree llamado con un puntero nulo

Copie tal cual el ejemplo que aqui en paginas atras colocan, pero tube que comentar esta linea (abajo), porque al compilar xHarbour NO reconoce esta funcion: hb_vfSize( cFileName ), alguna idea ... GRACIAS

curl_easy_setopt( hCurl, HB_CURLOPT_INFILESIZE, hb_vfSize( cFileName ) )

el codigo que uso es este:

function sFtpSubirFichero( cUrlFileName, cFileName, aUser, aPass )

local hCurl

local nResult

local aaUser := AllTrim(aUser)

local aaPass := AllTrim(aPass)

local aCadena := aaUser+":"+aaPass

curl_global_init()

if ! empty( hCurl := curl_easy_init() )

curl_easy_setopt( hCurl, HB_CURLOPT_PROTOCOLS, HB_CURLPROTO_SFTP)

curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrlFileName )

curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )

curl_easy_setopt( hCurl, HB_CURLOPT_UPLOAD )

curl_easy_setopt( hCurl, HB_CURLOPT_UL_FILE_SETUP, cFileName )

// curl_easy_setopt( hCurl, HB_CURLOPT_INFILESIZE, hb_vfSize( cFileName ) ) // lo marque porque hb_vfSize NO existe en xHB, que hacemos ??

curl_easy_setopt( hCurl, HB_CURLOPT_USERPWD, aCadena )

curl_easy_setopt( hCurl, HB_CURLOPT_TCP_KEEPALIVE, 1 )

curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYHOST, 0 )

curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, 0 )

curl_easy_setopt( hCurl, HB_CURLOPT_VERBOSE, 1 )

curl_easy_setopt( hCurl, HB_CURLOPT_USE_SSL, 0 )

if ( nResult := curl_easy_perform( hCurl ) ) == 0

nResult := curl_easy_dl_buff_get( hCurl )

else

? "error code:" + Str( nResult )

endif

endif

curl_global_cleanup()

return nResult

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Conectar a un SFTP con CURL usando xHarbour ...
Posted: Wed Jul 19, 2023 06:26 AM

Estimado Enrique,

Se genera un fichero .log ?

En caso afirmativo, por favor, c贸pialo aqui

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Conectar a un SFTP con CURL usando xHarbour ...
Posted: Wed Jul 19, 2023 07:30 AM

Saludos Antonio

Acabo de probar y no genera ningun .LOG, he probado con FWH 23.04 y aparece el error antes indicado, gracias.

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Conectar a un SFTP con CURL usando xHarbour ...
Posted: Wed Jul 19, 2023 08:34 AM

Saludos Antonio

El mismo error me sale al tratar de compilar con xHb el ejemplo TWITTER.PRG que viene en samples de FWH, ahi se usa CURL y me sale el mismo error ...

Enlazo las 2 librerias libcurl.lib que viene en FWH y hbcurl.lib que viene en xHb.

Quizas con este ejemplo sea mas facil de analizar, gracias.

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Conectar a un SFTP con CURL usando xHarbour ...
Posted: Wed Jul 19, 2023 04:39 PM

> Enlazo las 2 librerias libcurl.lib que viene en FWH y hbcurl.lib que viene en xHb

Puedes envi谩rmelas por favor, asi nos aseguramos que usamos las mismas

Busca y usa "wormhole app" desde google

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Conectar a un SFTP con CURL usando xHarbour ...
Posted: Wed Jul 19, 2023 04:52 PM
Saludos Antonio, aqui las LIBs

libcurl.lib
https://wormhole.app/9pXyE#gh5NADI8PC7IVnprLK8-0g
hbcurl.lib
https://wormhole.app/aoRno#IvOUN4epEhzCyu1WgNF-0Q

Como te mencione una prueba puede ser el ejemplo Twitter.prg que me bota el mismo error, GRACIAS
Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Conectar a un SFTP con CURL usando xHarbour ...
Posted: Wed Jul 19, 2023 05:03 PM

Si comento esta l铆nea, ya no aparece el error:

// curl_global_init()

Puedes probarlo y confirmarlo ?

gracias

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Conectar a un SFTP con CURL usando xHarbour ...
Posted: Wed Jul 19, 2023 05:13 PM
Enrique,

Cambia esta llamada:

curl_global_init()

por

curlglobalinit()

y a帽ade este c贸digo al final en la seccion de C:
Code (fw): Select all Collapse
#pragma BEGINDUMP

#include <hbapi.h>
#include <hbapiitm.h>
#include <hbapierr.h>
#include "c:\curl32\include\curl\curl.h"
#include "c:\harbour\contrib\hbcurl\hbcurl.ch"

static void * hb_curl_xgrab( size_t size )
{
聽 聽return size > 0 ? hb_xgrab( size ) : NULL;
}

static void hb_curl_xfree( void * p )
{
聽 聽if( p )
聽 聽 聽 hb_xfree( p );
}

static void * hb_curl_xrealloc( void * p, size_t size )
{
聽 聽return size > 0 ? ( p ? hb_xrealloc( p, size ) : hb_xgrab( size ) ) : NULL;
}

static char * hb_curl_strdup( const char * s )
{
聽 聽return hb_strdup( s );
}

static void * hb_curl_calloc( size_t nelem, size_t elsize )
{
聽 聽size_t size = nelem * elsize;
聽 聽void * ptr 聽= hb_xgrab( size );

聽 聽memset( ptr, '\0', size );

聽 聽return ptr;
}

HB_FUNC( CURLGLOBALINIT )
{
聽 聽hb_retnl( ( long ) curl_global_init_mem( hb_parnldef( 1, CURL_GLOBAL_ALL ),
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 hb_curl_xgrab,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 hb_curl_xfree,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 hb_curl_xrealloc,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 hb_curl_strdup,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 hb_curl_calloc ) );
}
As铆 ya no aparece el error :-)

Supongo que la versi贸n de xHarbour no hace esta comprobaci贸n sobre el puntero de memoria:
Code (fw): Select all Collapse
static void hb_curl_xfree( void * p )
{
聽 聽if( p )
聽 聽 聽 hb_xfree( p );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Conectar a un SFTP con CURL usando xHarbour ...
Posted: Wed Jul 19, 2023 05:35 PM

Probando ...

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Conectar a un SFTP con CURL usando xHarbour ...
Posted: Wed Jul 19, 2023 06:02 PM

Saludos Antonio

Ya no me bota ese mensaje que me saca del sistema, me da un error: 1, voy a revisar la documentacion de CURL quizas tenga algo que ver con el SFTP o directorio o algo

MUCHAS GRACIAS.

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Conectar a un SFTP con CURL usando xHarbour ...
Posted: Wed Oct 04, 2023 02:23 PM

Saludos

Al final tuvimos que usar Putty y linea de comandos, queriamos evitar usar una aplicacion externa, pero no encontramos solucion, si alguien tiene un ejemplo funcional de como subir archivos a un SFTP usando FWH y xHarbour, ojala lo pueda compartir

Gracias

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m

Continue the discussion