Page 2 of 5

Re: Conectar SFTP con CURL

PostPosted: Thu Mar 10, 2022 11:06 am
by pepe_garcia
Lo he probado con PSFTP y funciona con los parametros.
Gracias.

Re: Conectar SFTP con CURL

PostPosted: Thu Mar 10, 2022 11:42 am
by hmpaquito
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

Re: Conectar SFTP con CURL

PostPosted: Thu Mar 10, 2022 2:56 pm
by pepe_garcia
Gracias, lo volveré a probar a ver si me he puesto mal algún parametro.

Re: Conectar SFTP con CURL

PostPosted: Thu Mar 10, 2022 4:40 pm
by pepe_garcia
No funciona.

Re: Conectar SFTP con CURL

PostPosted: Thu Mar 10, 2022 7:20 pm
by hmpaquito
Por favor muestra el fuente, la parte del envio, tergiversando claves y direcciones electronicas

Re: Conectar SFTP con CURL

PostPosted: Thu Mar 10, 2022 7:27 pm
by hmpaquito
En la URL ¿ Estás prefijando como sftp:// ?

Re: Conectar SFTP con CURL

PostPosted: Fri Mar 11, 2022 1:57 pm
by horacio
Hola compañeros
Alguien pudo conectarse? usando el código propuesto genera un error "protocolo no soportado". Alguien pudo hacerlo funcionar?

Saludos

Re: Conectar SFTP con CURL

PostPosted: Sat Mar 12, 2022 12:23 am
by cnavarro
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.

Re: Conectar SFTP con CURL

PostPosted: Sat Mar 12, 2022 12:29 am
by albeiroval
Cristobal,

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

Saludos

Re: Conectar SFTP con CURL

PostPosted: Sat Mar 12, 2022 12:33 am
by cnavarro
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

Re: Conectar SFTP con CURL

PostPosted: Sun Mar 13, 2022 12:20 pm
by pepe_garcia
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: Select all  Expand view

#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
 

Re: Conectar SFTP con CURL

PostPosted: Sun Mar 13, 2022 1:05 pm
by cnavarro
Prueba este código, quita si lo encuentras necesario las lineas que he comentado y dime qué te contesta el servidor ( ? cResponse )

Code: Select all  Expand view

#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
 

Re: Conectar SFTP con CURL

PostPosted: Sun Mar 13, 2022 2:21 pm
by pepe_garcia
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

Re: Conectar SFTP con CURL

PostPosted: Sun Mar 13, 2022 2:52 pm
by pepe_garcia
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.

Re: Conectar SFTP con CURL

PostPosted: Sun Mar 13, 2022 7:47 pm
by pepe_garcia
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: Select all  Expand view

#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