Page 1 of 1

FTP

Posted: Thu Mar 12, 2009 12:49 am
by arturo_lopesoria
Helllo everybody
I need to get/put files from FTP site TO PC and viceversa.
If are not HMG or Harbour function to do that I could adapt some WinApi example in "C"Code and use it with PRAGMA, but, in this case I'll need some help for data types conversion.
What are your recomendation for this purpose?

Hola.
Necesito traer y poner archivos de un sitio FTP a la PC y viceversa.
En caso de que no exista algo implementado con HMG y/o Harbour, yo podria utilizar algun ejemplo de las funciones WinApi que existen en la red para lenguaje "C", e incorporarlas mediente PRAGMA. Aunque si este fuera el caso necesitaria algo de ayuda para adaptar el codigo ya que no soy bueno con la conversion de tipos.
Alguna recomendacion o idea al respecto?

GRACIAS / SALUDOS.

Re: FTP

Posted: Thu Mar 12, 2009 3:56 am
by Rathinagiri
Yes. You can do this using HBTIP.

From the sample program from the HBTIP source.

Code: Select all

/*
 * $Id: dnldftp.prg 8734 2008-06-15 21:11:36Z vszakats $
 */

/* DNLDftp.prg
   Download an file from an ftp server
*/

#include "common.ch"

FUNCTION MAIN( cFile)

   LOCAL lRet

   lRet := TRP20FTPEnv( cFile )
   ? lRet

RETURN nil

*+±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
*+
*+    Static Function TRP20FTPEnv()
*+
*+±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
*+
STATIC FUNCTION TRP20FTPEnv( cCarpeta )

   LOCAL aFiles
   LOCAL n
   LOCAL cUrl
   LOCAL cStr
   LOCAL lRetorno  := .T.
   LOCAL oUrl
   LOCAL oFTP
   LOCAL cUser
   LOCAL cServer
   LOCAL cPassword
   LOCAL cFile     := ""
   LOCAL lElim

   DEFAULT lElim TO .F.

   cServer   := "ftpserver" //change ftpserver to the real name  or ip of your ftp server
   cUser     := "ftpuser"  // change ftpuser to an valid user on ftpserer
   cPassword := "ftppass"  // change ftppass  to an valid password for ftpuser
   cUrl      := "ftp://" + cUser + ":" + cPassword + "@" + cServer

   // Leemos ficheros a enviar
   aFiles := { { cCarpeta, 1, 2, 3 } }
   //     aFiles := Directory( cCarpeta)

   IF Len( aFiles ) > 0

      oUrl              := tUrl():New( cUrl )
      oFTP              := tIPClientFtp():New( oUrl, .T. )
      oFTP:nConnTimeout := 20000
      oFTP:bUsePasv     := .T.

      // Comprobamos si el usuario contiene una @ para forzar el userid
      IF At( "@", cUser ) > 0
         oFTP:oUrl:cServer   := cServer
         oFTP:oUrl:cUserID   := cUser
         oFTP:oUrl:cPassword := cPassword
      ENDIF

      IF oFTP:Open( cUrl )
         FOR each cFile IN afiles
            IF !oFtp:DownloadFile( cFile[ 1 ] )
               lRetorno := .F.
               EXIT
            ELSE
               lRetorno := .t.
            ENDIF
         NEXT
         oFTP:Close()
      ELSE
         cStr := "No se ha podido conectar con el servidor FTP" + " " + oURL:cServer
         IF oFTP:SocketCon == NIL
            cStr += Chr( 13 ) + Chr( 10 ) + "Conexión no inicializada"
         ELSEIF hb_InetErrorCode( oFTP:SocketCon ) == 0
            cStr += Chr( 13 ) + Chr( 10 ) + "Respuesta del servidor:" + " " + oFTP:cReply
         ELSE
            cStr += Chr( 13 ) + Chr( 10 ) + "Error en la conexión:" + " " + hb_InetErrorDesc( oFTP:SocketCon )
         ENDIF
         ? cStr
         lRetorno := .F.
      ENDIF
   ENDIF
RETURN lRetorno


Re: FTP

Posted: Thu Mar 12, 2009 6:35 am
by arturo_lopesoria
Thanks Rathinagiri very much
I'm already compiled the example you sendme without errors!
tomorrow I wil probe it with proper parameters.
Saludos.