Page 1 of 1

ftp upload/download

PostPosted: Mon Feb 07, 2022 3:23 pm
by damianodec
Hi,
any example of ftp upload/download ?

thank you

Re: ftp upload/download

PostPosted: Mon Feb 07, 2022 9:39 pm
by cmsoft
Code: Select all  Expand view

***************************************
** Descargar archivo desde la web
function Descargar(cUrl,cDestino)
LOCAL nRet
DELETEURLCACHEENTRY(  cUrl )
nRet := DOWNLOADFILE( cUrl, cDestino)
RETURN nRet = 0


#pragma BEGINDUMP
#include <Windows.h>
#include <hbapi.h>
#include <urlmon.h>
HB_FUNC( DOWNLOADFILE )
{
        HRESULT hr;      
        hr = URLDownloadToFile( NULL, hb_parc( 1 ), hb_parc( 2 ), 0, NULL ) ;
        hb_retnl( hr ) ;
}
#pragma ENDDUMP

DLL STATIC FUNCTION DELETEURLCACHEENTRY( cUrl AS LPSTR ) AS BOOL;
PASCAL FROM "DeleteUrlCacheEntryA" LIB "wininet.dll"

*****************************************
*** Conectar al servidor FTP
FUNCTION ConectaServerFTP(cNomSer,cNomUsr,cClaUsr,oFtp) //oFtp pasar por referencia
LOCAL cServer, cUser, cPassword, oUrl, cUrl
cServer := cNomSer
cUser := cNomUsr
cPassword := cClaUsr
cUrl := "ftp://" + cUser + ":" + cPassword + "@" + cServer
cUser:= strtran(cUser,"@","&at;")
oUrl := tUrl():New( cUrl )
IF At( "@", cUser ) > 0
   oUrl:cUserID := strtran(cUser,"&at;","@")
   oUrl:cPassword := cPassword
ENDIF
oFTP := tIPClientFtp():New( oUrl, .T. )
oFTP:nConnTimeout := 20000
oFTP:bUsePasv := .T.
oFtp:bTrace := {|| .t.}
oFTP:Open( )
IF oFtp <> NIL
   RETURN .T.
ENDIF
RETURN .F.

******************************************************************************
FUNCTION SubeArchivoFtp(cFileOri,cFileDes,oFtp)
oFtp:Dele( cFileDes )
oFtp:UpLoadFile( cFileOri, cFileDes )
RETURN .T.
 

Re: ftp upload/download

PostPosted: Tue Feb 08, 2022 2:56 pm
by damianodec
thank you!

Re: ftp upload/download

PostPosted: Sat Feb 19, 2022 7:23 pm
by santidedos
Hola Cesar

Quise compilar el módulo pero me tira el siguiente error

Code: Select all  Expand view

Turbo Incremental Link 6.70 Copyright (c) 1997-2014 Embarcadero Technologies, Inc.
Error: Unresolved external 'URLDownloadToFileA' referenced from C:\FWH1701\SAMPLES\FTP2.OBJ
Error: Unable to perform link
* Linking errors *
 

Alguna idea? desde ya muchísimas gracias

Saludos

Re: ftp upload/download

PostPosted: Sat Feb 19, 2022 8:06 pm
by cmsoft
santidedos wrote:Quise compilar el módulo pero me tira el siguiente error

Tienes que enlazar la librería de Borland urlmon.lib

Re: ftp upload/download

PostPosted: Sat Feb 19, 2022 9:05 pm
by santidedos
Ahí compiló. Gracias!!