Page 1 of 1

Descargar archivo de la nube

Posted: Fri Oct 01, 2021 3:04 pm
by acuellar
Estimados

Con ftpdown.prg descarga si se tiene instalado Apache24

Code: Select all | Expand


 #ifdef __PLATFORM__WINDOWS
   #include "c:\harbour\contrib\hbcurl\hbcurl.ch"
#else
   #include "/usr/include/harbour/hbcurl.ch"
#endif

function main()

    local hCurl
    local cUrl  := 'https://raw.githubusercontent.com/FiveTechSoft/FWH_tools/master/README.md' 
    local cFile     := hb_GetEnv( 'PRGPATH' ) + '/myreadme.md'
   
    if ! empty( hCurl := curl_easy_init() )  
 
        curl_easy_setopt( hCurl, HB_CURLOPT_DOWNLOAD )
        curl_easy_setopt( hCurl, HB_CURLOPT_URL, cURL )    
       
        curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .f. )
        curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYHOST, .f. )
        curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION )        
        curl_easy_setopt( hCurl, HB_CURLOPT_FILETIME, 1)
        curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, cFile)
        curl_easy_setopt( hCurl, HB_CURLOPT_NOPROGRESS, .f. )
        curl_easy_setopt( hCurl, HB_CURLOPT_VERBOSE, .f. )         
        curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR , .t. )  // Change cUrl Dummy      
       
        nRet := curl_easy_perform( hCurl )

       
        if nRet == HB_CURLE_OK  //  HB_CURLE_OK == 0           
           ? 'Total Time:', curl_easy_getinfo( hCurl, HB_CURLINFO_TOTAL_TIME )
           ? 'Download to -> ', cFile
        else
           ? 'Error ->', curl_easy_strerror( nRet )
        endif   

        curl_global_cleanup()   
       
    endif   
   
return nil
 

Cómo hacer para que desde un sistema de escritorio lo guarde en el equipo cliente en una ubicación especifica sin tener Apache24 instalado?
Desde el sistema lo ejecuto asi:

Code: Select all | Expand


  oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
  oHttp:Open("GET","http://"+IPServer+"/admcon/ftpdown.prg", .f. )
  oHttp:Send()
 


Gracias por la ayuda.

Re: Descargar archivo de la nube

Posted: Sat Oct 02, 2021 12:27 pm
by cmsoft
Hola Acuellar:
En un post anterior http://forums.fivetechsupport.com/viewtopic.php?f=6&t=40871&sid=12f0b4c64d5ed2cf877dd5d69d9e3790 puse un ejemplo para descargar por ftp

Code: Select all | Expand


#include "hbcurl.ch"
#include "fivewin.ch"

function Main()

  curl_global_init()
  callSFTP( "ftp.misitio.com.ar/archivos/miarchivo.jpg" )

   curl_global_cleanup()

return nil

function callSFTP( cServer )
LOCAL curlHandle, cFtpsURL := cServer, cFile, nFSize, cRet, nPort := 21 // En SFTP cambio por 22 o 122 que es el puerto que me abrieron
LOCAL curlErr
cFile := "C:\misdescargas\DOWNLOAD.JPG"

curlHandle:=curl_easy_init()
IF EMPTY(curlHandle)
  MsgStop("Error al iniciar cURL.","Error")  
  RETURN nil
ENDIF
curl_easy_reset( curlHandle )

curl_easy_setopt(curlHandle, HB_CURLOPT_URL, cftpsURL)
curl_easy_setopt(curlHandle, HB_CURLOPT_USERPWD, "usuario:password" )
curl_easy_setopt(curlHandle, HB_CURLOPT_PORT, nPort)

curl_easy_setopt(curlHandle, HB_CURLOPT_FOLLOWLOCATION, .T. )
curl_easy_setopt(curlHandle, HB_CURLOPT_SSL_VERIFYPEER, .F. )
curl_easy_setopt(curlHandle, HB_CURLOPT_SSL_VERIFYHOST, .F. )


curl_easy_setopt(curlHandle, HB_CURLOPT_DOWNLOAD, 1)
curl_easy_setopt(curlHandle, HB_CURLOPT_PROTOCOLS, HB_CURLPROTO_FTP )  // En SFTP cambio por  HB_CURLPROTO_SFTP
curl_easy_setopt(curlHandle, HB_CURLOPT_DL_FILE_SETUP, cFile)


/* Do everything */
curlErr := curl_easy_perform(curlHandle)
 
/* Report any errors */

cRet:=curl_easy_strerror(curlErr)
MsgInfo(cRet)

//Close
curl_global_cleanup( curlHandle )
RETURN nil
 

Funciona bien con servidor ftp, pero no me ha funcionado con servidores SFTP
Espero te ayude

Re: Descargar archivo de la nube

Posted: Sat Oct 02, 2021 12:45 pm
by acuellar
Muchas Gracias Estimado Cesar

Ya logré hacerlo por FTP con éste sencillo ejemplo

Code: Select all | Expand


   oCon:=Turl():New("ftp://"+cusuario+":"+cpass+"@"+cftpsite)
   oFTP:=TIpClientFtp():New(oCon, .f.)
   oFTP:open()
   oFtp:DownloadFile(cDir+cFile,cFile)
   oFtp:close()
 


Gracias una vez mas