Conectar SFTP con CURL

Re: Conectar SFTP con CURL

Postby pepe_garcia » Thu Mar 10, 2022 11:06 am

Lo he probado con PSFTP y funciona con los parametros.
Gracias.
pepe_garcia
 
Posts: 27
Joined: Thu Feb 20, 2014 12:40 pm

Re: Conectar SFTP con CURL

Postby hmpaquito » 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
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Conectar SFTP con CURL

Postby pepe_garcia » Thu Mar 10, 2022 2:56 pm

Gracias, lo volveré a probar a ver si me he puesto mal algún parametro.
pepe_garcia
 
Posts: 27
Joined: Thu Feb 20, 2014 12:40 pm

Re: Conectar SFTP con CURL

Postby pepe_garcia » Thu Mar 10, 2022 4:40 pm

No funciona.
pepe_garcia
 
Posts: 27
Joined: Thu Feb 20, 2014 12:40 pm

Re: Conectar SFTP con CURL

Postby hmpaquito » Thu Mar 10, 2022 7:20 pm

Por favor muestra el fuente, la parte del envio, tergiversando claves y direcciones electronicas
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Conectar SFTP con CURL

Postby hmpaquito » Thu Mar 10, 2022 7:27 pm

En la URL ¿ Estás prefijando como sftp:// ?
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Conectar SFTP con CURL

Postby horacio » Fri Mar 11, 2022 1:57 pm

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

Saludos
horacio
 
Posts: 1358
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: Conectar SFTP con CURL

Postby cnavarro » 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
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Conectar SFTP con CURL

Postby albeiroval » 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
User avatar
albeiroval
 
Posts: 359
Joined: Tue Oct 16, 2007 5:51 pm
Location: Barquisimeto - Venezuela

Re: Conectar SFTP con CURL

Postby cnavarro » 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
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Conectar SFTP con CURL

Postby pepe_garcia » 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: 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
 
pepe_garcia
 
Posts: 27
Joined: Thu Feb 20, 2014 12:40 pm

Re: Conectar SFTP con CURL

Postby cnavarro » Sun Mar 13, 2022 1: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: 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
 
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
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Conectar SFTP con CURL

Postby pepe_garcia » Sun Mar 13, 2022 2: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
pepe_garcia
 
Posts: 27
Joined: Thu Feb 20, 2014 12:40 pm

Re: Conectar SFTP con CURL

Postby pepe_garcia » Sun Mar 13, 2022 2: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.
pepe_garcia
 
Posts: 27
Joined: Thu Feb 20, 2014 12:40 pm

Re: Conectar SFTP con CURL

Postby pepe_garcia » Sun Mar 13, 2022 7: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: 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
 
pepe_garcia
 
Posts: 27
Joined: Thu Feb 20, 2014 12:40 pm

PreviousNext

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 81 guests