FTP

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
arturo_lopesoria
Posts: 23
Joined: Tue Sep 09, 2008 3:05 am
Location: Mexico

FTP

Post 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.

User avatar
Rathinagiri
Posts: 5324
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 200 times
Been thanked: 210 times
Contact:

Post 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

East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
arturo_lopesoria
Posts: 23
Joined: Tue Sep 09, 2008 3:05 am
Location: Mexico

Post 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.

Post Reply