FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Conectar SFTP con CURL
Posts: 27
Joined: Thu Feb 20, 2014 12:40 PM
Re: Conectar SFTP con CURL
Posted: Thu Mar 10, 2022 11:06 AM

Lo he probado con PSFTP y funciona con los parametros.
Gracias.

Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Conectar SFTP con CURL
Posted: Thu Mar 10, 2022 11:42 AM

Yo no lo he probado pero el máster Navarro puso un ejemplo aqui: https://groups.google.com/g/harbour-use ... JY7zJoAQAJ

Añadele los parámetros que no tienes o mejor, coge el ejemplo de D. Cristóbal y ponle tus parámetros de autenticacion.
Ya nos contarás

Posts: 27
Joined: Thu Feb 20, 2014 12:40 PM
Re: Conectar SFTP con CURL
Posted: Thu Mar 10, 2022 02:56 PM

Gracias, lo volveré a probar a ver si me he puesto mal algún parametro.

Posts: 27
Joined: Thu Feb 20, 2014 12:40 PM
Re: Conectar SFTP con CURL
Posted: Thu Mar 10, 2022 04:40 PM

No funciona.

Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Conectar SFTP con CURL
Posted: Thu Mar 10, 2022 07:20 PM

Por favor muestra el fuente, la parte del envio, tergiversando claves y direcciones electronicas

Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Conectar SFTP con CURL
Posted: Thu Mar 10, 2022 07:27 PM
En la URL ¿ Estás prefijando como sftp:// ?
Posts: 1364
Joined: Wed Jun 21, 2006 12:39 AM
Re: Conectar SFTP con CURL
Posted: Fri Mar 11, 2022 01:57 PM

Hola compañeros
Alguien pudo conectarse? usando el código propuesto genera un error "protocolo no soportado". Alguien pudo hacerlo funcionar?

Saludos

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Conectar SFTP con CURL
Posted: Sat Mar 12, 2022 12:23 AM

Te aseguro que funciona de lujo
De hecho, los usuarios de FivEdit, lo sabrán ya que tiene la posibilidad de conectar a servidores SFTP y editar incluso directamente los ficheros alojados en dichos servidores, y, en breve a GitHub también.

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 400
Joined: Tue Oct 16, 2007 05:51 PM
Re: Conectar SFTP con CURL
Posted: Sat Mar 12, 2022 12:29 AM

Cristobal,

Por favor puedes poner un ejemplo funcional, incluida la dll que usas.

Saludos

Saludos,
Regards,

Albeiro Valencia
www.avcsistemas.com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Conectar SFTP con CURL
Posted: Sat Mar 12, 2022 12:33 AM

Este es el ejemplo que publiqué, lee mi post hasta el final porque si no es posible que obtengas algún mensaje parecido a "protocolo no soportado"

https://groups.google.com/g/harbour-use ... JY7zJoAQAJ
Las DLLs que uso ( hay algunas que no te hacen falta , te pongo el enlace a las que necesita FivEdit para funcionar )

https://bitbucket.org/fivetech/fivewin- ... E_DLLS.zip

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 27
Joined: Thu Feb 20, 2014 12:40 PM
Re: Conectar SFTP con CURL
Posted: Sun Mar 13, 2022 12:20 PM
Buenos días,

Gracias por las contestaciones, pero soy incapaz de que funcione. Es más, no se si se conecta o no a mi servidor SFTP.
Lo que quiero es una funcion que sea capaz de subir o bajar ficheros a una carpeta concreta de una web, usando SFTP.
Estoy ahora probando con el ejmplo citado. Lo que pretendo es llegar hasta la carpeta del servidor 000.000.000.000 y coger de la carpeta FILES el fichero prueba.txt. Bajandolo despues a la carpeta PRG del disco duro con el nombre prueba2.txt
Si alguien me puede ayudar lo agradeceria muchisimo
Gracias
Code (fw): Select all Collapse
#include "c:\harbour\include\hbcurl2.ch"

function Main()

  curl_global_init()

  ? FtpUploadFile( "sftp://000.000.000.000/files/prueba.txt", hb_GetEnv( "c:\prg" ) + "\prueba2.txt" )

   curl_global_cleanup()

return nil

function FtpUploadFile( cUrlFileName, cFileName )

   local hCurl, uValue, nResult

   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 ) )
      curl_easy_setopt( hCurl, HB_CURLOPT_USERPWD, "username:password" )
      curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, .T. )
      curl_easy_setopt( hCurl, HB_CURLOPT_FILETIME, .T. )
      curl_easy_setopt( hCurl, HB_CURLOPT_NOPROGRESS, 0 )
      curl_easy_setopt( hCurl, HB_CURLOPT_VERBOSE, .F. )

      if ( nResult := curl_easy_perform( hCurl ) ) == 0
         curl_easy_dl_buff_get( hCurl )
      else
         ? "error code:" + Str( nResult )
      endif
   endif

return nResult == HB_CURLE_OK
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Conectar SFTP con CURL
Posted: Sun Mar 13, 2022 01:05 PM
Prueba este código, quita si lo encuentras necesario las lineas que he comentado y dime qué te contesta el servidor ( ? cResponse )

Code (fw): Select all Collapse
#include "c:\harbour\include\hbcurl2.ch"

function Main()

  curl_global_init()

  ? FtpUploadFile( "sftp://000.000.000.000/files/prueba.txt", hb_GetEnv( "c:\prg" ) + "\prueba2.txt" )

   curl_global_cleanup()

return nil

function FtpUploadFile( cUrlFileName, cFileName )

   local hCurl, uValue, nResult
   local cResult  := ""

   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 )                                           // Es un download, no?
      //curl_easy_setopt( hCurl, HB_CURLOPT_UL_FILE_SETUP, cFileName )
      //curl_easy_setopt( hCurl, HB_CURLOPT_INFILESIZE, hb_vfSize( cFileName ) )   // Qué valor devuelve hb_vfSize( cFileName ) ?
      curl_easy_setopt( hCurl, HB_CURLOPT_USERPWD, "username:password" )
      //curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, .T. )
      //curl_easy_setopt( hCurl, HB_CURLOPT_FILETIME, .T. )
      //curl_easy_setopt( hCurl, HB_CURLOPT_NOPROGRESS, 0 )
      //curl_easy_setopt( hCurl, HB_CURLOPT_VERBOSE, .F. )
         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
           cResult := curl_easy_dl_buff_get( hCurl )
           ? cResult
      else
         ? "error code:" + Str( nResult )
      endif
   endif

return nResult == HB_CURLE_OK
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 27
Joined: Thu Feb 20, 2014 12:40 PM
Re: Conectar SFTP con CURL
Posted: Sun Mar 13, 2022 02:21 PM

Hola,

Si, es un donwload. Con ese codigo tampoco funciona, de hecho se ejecuta el programa y no hace nada, no da ningún mensaje. Si quieres te mando el codigo completo con todos los datos, más que nada para que lo intente un experto.

Gracias

Posts: 27
Joined: Thu Feb 20, 2014 12:40 PM
Re: Conectar SFTP con CURL
Posted: Sun Mar 13, 2022 02:52 PM

Acabo de hacerlo funcionar con UPLOAD. El problema era que no accede al subdirectorio dentro del SFTP que se le indica, digamos que accede a sftp://000.000.000.000 , pero no a sftp://000.000.000.000/files.
Alguna indicacion que me pueda ayudar.
Gracias.

Posts: 27
Joined: Thu Feb 20, 2014 12:40 PM
Re: Conectar SFTP con CURL
Posted: Sun Mar 13, 2022 07:47 PM
Hola Cristobal,
Con este codigo SFTP funciona perfectamente subiendo el fichero que se indica al servidor SFTP.
Ahora estoy liado con el donwload que es el que no consigo.
Espero tus indicaciones.
Muchas gracias
Code (fw): Select all Collapse
#include "c:\harbour\include\hbcurl2.ch"

function Main()

  curl_global_init()

  ? FtpUploadFile( "sftp://000.000.000.000/files/PRUEBAS/prueba.txt", "c:\prueba\prueba.txt" )

  //? FtpDonwLoadFile( "sftp://000.000.000.000/files/PRUEBAS/prueba.txt", "c:\prueba\prueba.txt" )

   curl_global_cleanup()

return nil

function FtpUploadFile( cUrlFileName, cFileName )

   local hCurl, uValue, nResult
   local cResult  := ""

   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 ) )   
      curl_easy_setopt( hCurl, HB_CURLOPT_USERPWD, "USUARIO:CONTRASEÑA" )
      //curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, .T. )
      //curl_easy_setopt( hCurl, HB_CURLOPT_FILETIME, .T. )
      //curl_easy_setopt( hCurl, HB_CURLOPT_NOPROGRESS, 0 )
      //curl_easy_setopt( hCurl, HB_CURLOPT_VERBOSE, .F. )
      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
           cResult := curl_easy_dl_buff_get( hCurl )
           //? cResult
      else
         ? "error code:" + Str( nResult )
      endif
   endif

return nResult == HB_CURLE_OK

function FtpDoNwLoadFile( cUrlFileName, cFileName )

   local hCurl, uValue, nResult
   local cResult  := ""

   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_USERPWD, "USUARIO:CONTRASEÑA" )
      curl_easy_setopt( hCurl, HB_CURLOPT_UL_FILE_SETUP, cFileName )
      curl_easy_setopt( hCurl, HB_CURLOPT_INFILESIZE, hb_vfSize( cFileName ) )   // Qué valor devuelve hb_vfSize( cFileName ) ?
      curl_easy_setopt( hCurl, HB_CURLOPT_DOWNLOAD )
      //curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, .T. )
      //curl_easy_setopt( hCurl, HB_CURLOPT_FILETIME, .T. )
      //curl_easy_setopt( hCurl, HB_CURLOPT_NOPROGRESS, 0 )
      //curl_easy_setopt( hCurl, HB_CURLOPT_VERBOSE, .F. )
      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
           cResult := curl_easy_dl_buff_get( hCurl )
           ? cResult
      else
         ? "error code:" + Str( nResult )
      endif
   endif

return nResult == HB_CURLE_OK