ecore_con: add example for ftp upload.
authorSrivardhan Hebbar <sri.hebbar@samsung.com>
Wed, 25 Mar 2015 18:26:41 +0000 (19:26 +0100)
committerCedric BAIL <cedric@osg.samsung.com>
Wed, 25 Mar 2015 18:40:41 +0000 (19:40 +0100)
Summary:
Added example for ftp upload. In the .gitignore only 2 files added which were missing. The differences it is showing is cos of reordering. I did ls and redirected the file to gitignore. So the files got reordered.

Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com>
Reviewers: cedric

Reviewed By: cedric

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D2223

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/examples/ecore/.gitignore
src/examples/ecore/ecore_con_url_ftp_example.c [new file with mode: 0644]

index 497f0f3..700be32 100644 (file)
@@ -3,39 +3,41 @@
 /ecore_audio_playback
 /ecore_audio_to_ogg
 /ecore_client_bench
+/ecore_compose_get_example
+/ecore_con_client_example
 /ecore_con_client_simple_example
 /ecore_con_lookup_example
+/ecore_con_server_example
 /ecore_con_server_http_example
 /ecore_con_server_simple_example
 /ecore_con_url_cookies_example
 /ecore_con_url_download_example
+/ecore_con_url_ftp_example
 /ecore_con_url_headers_example
 /ecore_evas_basics_example
 /ecore_evas_buffer_example_01
 /ecore_evas_buffer_example_02
 /ecore_evas_callbacks
 /ecore_evas_ews_example
-/ecore_evas_object_example
-/ecore_evas_window_sizes_example
 /ecore_evas_extn_plug_example
 /ecore_evas_extn_socket_example
+/ecore_evas_object_example
+/ecore_evas_window_sizes_example
 /ecore_event_example_01
 /ecore_event_example_02
 /ecore_exe_example
 /ecore_exe_example_child
 /ecore_fd_handler_example
+/ecore_fd_handler_gnutls_example
+/ecore_file_download_example
+/ecore_getopt_example
 /ecore_idler_example
+/ecore_imf_example
 /ecore_job_example
+/ecore_pipe_gstreamer_example
 /ecore_pipe_simple_example
 /ecore_poller_example
 /ecore_server_bench
 /ecore_thread_example
 /ecore_time_functions_example
 /ecore_timer_example
-/ecore_con_client_example
-/ecore_con_server_example
-/ecore_file_download_example
-/ecore_imf_example
-/ecore_pipe_gstreamer_example
-/ecore_getopt_example
-/ecore_compose_get_example
diff --git a/src/examples/ecore/ecore_con_url_ftp_example.c b/src/examples/ecore/ecore_con_url_ftp_example.c
new file mode 100644 (file)
index 0000000..d3a1488
--- /dev/null
@@ -0,0 +1,83 @@
+//Compile with:
+// gcc -o ecore_con_url_ftp_example ecore_con_url_ftp_example.c `pkg-config --libs --cflags ecore ecore-con eina`
+
+#include <stdio.h>
+#include <Eina.h>
+#include <Ecore.h>
+#include <Ecore_Con.h>
+
+static Eina_Bool
+_url_data_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
+{
+   Ecore_Con_Event_Url_Data *url_data = event_info;
+   int i;
+
+   for (i = 0; i < url_data->size; i++)
+     printf("%c", url_data->data[i]);
+
+   return EINA_TRUE;
+}
+
+static Eina_Bool
+_url_complete_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
+{
+   Ecore_Con_Event_Url_Complete *url_complete = event_info;
+
+   printf("\n");
+   printf("upload completed with status code: %d\n", url_complete->status);
+
+   ecore_main_loop_quit();
+
+   return EINA_TRUE;
+}
+
+int
+main(int argc, const char *argv[])
+{
+   Ecore_Con_Url *ec_url = NULL;
+   const char *file, *user, *passwd, *dir;
+
+   if (argc < 5)
+     {
+        printf("./ecore_con_url_ftp <ftp_server_address> <username> <password> <file> <directory(optional)>\n");
+        return -1;
+     }
+
+   ecore_con_init();
+   ecore_con_url_init();
+
+   ec_url = ecore_con_url_new(argv[1]);
+   if (!ec_url)
+     {
+        printf("error when creating ecore con url object.\n");
+        goto end;
+     }
+
+   user = argv[2];
+   passwd = argv[3];
+   file = argv[4];
+   dir = argv[5];
+
+   ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _url_data_cb, NULL);
+   ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, NULL);
+
+   ecore_con_url_verbose_set(ec_url, EINA_TRUE);
+   ecore_con_url_ftp_use_epsv_set(ec_url, EINA_TRUE);
+
+   if( !ecore_con_url_ftp_upload(ec_url, file, user, passwd, dir))
+     {
+        printf("could not realize request.\n");
+        goto free_ec_url;
+     }
+
+   ecore_main_loop_begin();
+
+free_ec_url:
+   ecore_con_url_free(ec_url);
+end:
+   ecore_con_url_shutdown();
+   ecore_con_shutdown();
+
+   return 0;
+}
+