• Miércoles 15 de Mayo de 2024, 04:53

Autor Tema:  Subir Un Archivo Por Ftp  (Leído 1396 veces)

dieguito

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Subir Un Archivo Por Ftp
« en: Domingo 8 de Abril de 2007, 17:00 »
0
Que tal gente!. Hay alguna librería para subir archivos por FTP ? Solo necesito subir un archivo nada mas.

Gracias

su -

  • Moderador
  • ******
  • Mensajes: 2349
    • Ver Perfil
Re: Subir Un Archivo Por Ftp
« Respuesta #1 en: Domingo 8 de Abril de 2007, 17:08 »
0
Por favor, usa el buscador del foro para no repetir temas.

http://foros.solocodigo.com/index.php?showtopic=23038&hl=ftp
*******PELIGRO LEE ESTO!!*******

There is no place like 127.0.0.1

Conecto luego existo, no conecto luego insisto.

dieguito

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Re: Subir Un Archivo Por Ftp
« Respuesta #2 en: Domingo 8 de Abril de 2007, 17:41 »
0
Busque en el foro, puse FTP y solo sale mi post.

Otra cosa buscando un poco encontre las librerias CURL, y estoy probando un ejemplo de ellos pero no me compila.

Código: Text
  1.  
  2. localhost ~ # gcc ftpupload.c
  3.  
  4. ftpupload.c: In function 'main':
  5. ftpupload.c:64: error: 'TRUE' undeclared (first use in this function)
  6. ftpupload.c:64: error: (Each undeclared identifier is reported only once
  7. ftpupload.c:64: error: for each function it appears in.)
  8. ftpupload.c:101:2: warning: no newline at end of file
  9.  
  10.  

Código: Text
  1.  
  2. localhost ~ # cat ftpupload.c
  3.  
  4. /*****************************************************************************
  5.   *                                  _   _ ____  _
  6.   *  Project                     ___| | | |  _ \| |
  7.   *                             / __| | | | |_) | |
  8.   *                            | (__| |_| |  _ <| |___
  9.   *                             \___|\___/|_| \_\_____|
  10.   *
  11.   * $Id: ftpupload.c,v 1.7 2005/01/20 14:24:56 bagder Exp $
  12.   */
  13.  
  14.  #include <stdio.h>
  15.  
  16.  #include <curl/curl.h>
  17. #include <sys/types.h>
  18.  #include <sys/stat.h>
  19. #include <fcntl.h>
  20.  
  21. /*
  22. * This example shows an FTP upload, with a rename of the file just after
  23.  * a successful upload.
  24.  *
  25.   * Example based on source code provided by Erick Nuwendam. Thanks!
  26.  */
  27.  
  28.  #define LOCAL_FILE      "/tmp/uploadthis.txt"
  29.  #define UPLOAD_FILE_AS  "while-uploading.txt"
  30.  #define REMOTE_URL      "ftp://localhost/"  UPLOAD_FILE_AS
  31.  #define RENAME_FILE_TO  "renamed-and-fine.txt"
  32.  
  33.  int main(int argc, char **argv)
  34.  {
  35.    CURL *curl;
  36.    CURLcode res;
  37.    FILE *ftpfile;
  38.    FILE * hd_src&#59;
  39.    int hd&#59;
  40.    struct stat file_info;
  41.  
  42.    struct curl_slist *headerlist=NULL;
  43.    char buf_1 [] = "RNFR " UPLOAD_FILE_AS;
  44.    char buf_2 [] = "RNTO " RENAME_FILE_TO;
  45.  
  46.    /* get the file size of the local file */
  47.    hd = open(LOCAL_FILE, O_RDONLY)&#59;
  48.    fstat(hd, &file_info);
  49.    close(hd)&#59;
  50.  
  51.    /* get a FILE * of the same file, could also be made with
  52.       fdopen() from the previous descriptor, but hey this is just
  53.       an example! */
  54.    hd_src = fopen(LOCAL_FILE, "rb");
  55.  
  56.    /* In windows, this will init the winsock stuff */
  57.    curl_global_init(CURL_GLOBAL_ALL);
  58.  
  59.    /* get a curl handle */
  60.    curl = curl_easy_init();
  61.    if(curl) {
  62.      /* build a list of commands to pass to libcurl */
  63.      headerlist = curl_slist_append(headerlist, buf_1);
  64.      headerlist = curl_slist_append(headerlist, buf_2);
  65.  
  66.      /* enable uploading */
  67.      curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE)&#59;
  68.  
  69.      /* specify target */
  70.      curl_easy_setopt(curl,CURLOPT_URL, REMOTE_URL);
  71.  
  72.      /* pass in that last of FTP commands to run after the transfer */
  73.      curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
  74.  
  75.      /* now specify which file to upload */
  76.      curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
  77.  
  78.      /* NOTE: if you want this example to work on Windows with libcurl as a
  79.         DLL, you MUST also provide a read callback with
  80.         CURLOPT_READFUNCTION. Failing to do so will give you a crash since a
  81.         DLL may not use the variable's memory when passed in to it from an app
  82.         like this. */
  83.  
  84.      /* Set the size of the file to upload (optional).  If you give a *_LARGE
  85.         option you MUST make sure that the type of the passed-in argument is a
  86.         curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
  87.         make sure that to pass in a type 'long' argument. */
  88.      curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
  89.                       (curl_off_t)file_info.st_size);
  90.  
  91.      /* Now run off and do what you've been told! */
  92.      res = curl_easy_perform(curl);
  93.  
  94.      /* clean up the FTP commands list */
  95.      curl_slist_free_all (headerlist);
  96.  
  97.      /* always cleanup */
  98.      curl_easy_cleanup(curl);
  99.    }
  100.    fclose(hd_src); /* close the local file */
  101.  
  102.    curl_global_cleanup();
  103.    return 0;
  104. }
  105.  
  106.  

su -

  • Moderador
  • ******
  • Mensajes: 2349
    • Ver Perfil
Re: Subir Un Archivo Por Ftp
« Respuesta #3 en: Domingo 8 de Abril de 2007, 19:15 »
0
Viste el url que te puse?

Para compilar:

gcc `curl-config --cc --cflags --libs` -o ftpupload ftpupload.c
*******PELIGRO LEE ESTO!!*******

There is no place like 127.0.0.1

Conecto luego existo, no conecto luego insisto.

dieguito

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Re: Subir Un Archivo Por Ftp
« Respuesta #4 en: Domingo 8 de Abril de 2007, 22:52 »
0
Si lo vi. pero igual no me compila con esa forma. Pero leyendo lo pude compilar asi.

# gcc archiv.c -o archivo -lcurl


Te hago otra consulta, yo estoy trabajando con kdevelop con un proyecto qmake esto se puede hacer tambien ? porque no encuentro la manera de compilarlo con kdevelop con el -lcurl.

Saludos

su -

  • Moderador
  • ******
  • Mensajes: 2349
    • Ver Perfil
Re: Subir Un Archivo Por Ftp
« Respuesta #5 en: Domingo 8 de Abril de 2007, 23:55 »
0
Nunca he usado kdevelop pero supongo que con ponerlo en el Makefile y configure.sh es suficiente.
*******PELIGRO LEE ESTO!!*******

There is no place like 127.0.0.1

Conecto luego existo, no conecto luego insisto.