1
/*****************************************************************************
3
* Project ___| | | | _ \| |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
8
* $Id: lib505.c,v 1.4 2004/02/05 12:34:17 bagder Exp $
13
#ifdef HAVE_SYS_SOCKET_H
14
#include <sys/socket.h>
16
#ifdef HAVE_SYS_TYPES_
17
#include <sys/types.h>
19
#ifdef HAVE_SYS_STAT_H
31
* This example shows an FTP upload, with a rename of the file just after
32
* a successful upload.
34
* Example based on source code provided by Erick Nuwendam. Thanks!
43
struct stat file_info;
45
struct curl_slist *headerlist=NULL;
46
const char *buf_1 = "RNFR 505";
47
const char *buf_2 = "RNTO 505-forreal";
49
/* get the file size of the local file */
50
hd = stat(arg2, &file_info);
52
/* can't open file, bail out */
56
if(! file_info.st_size) {
57
fprintf(stderr, "WARNING: file %s has no size!\n", arg2);
61
/* get a FILE * of the same file, could also be made with
62
fdopen() from the previous descriptor, but hey this is just
64
hd_src = fopen(arg2, "rb");
66
return -2; /* if this happens things are major weird */
69
/* In windows, this will init the winsock stuff */
70
curl_global_init(CURL_GLOBAL_ALL);
72
/* get a curl handle */
73
curl = curl_easy_init();
75
/* build a list of commands to pass to libcurl */
76
headerlist = curl_slist_append(headerlist, buf_1);
77
headerlist = curl_slist_append(headerlist, buf_2);
79
/* enable uploading */
80
curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
83
curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE) ;
86
curl_easy_setopt(curl,CURLOPT_URL, URL);
88
/* pass in that last of FTP commands to run after the transfer */
89
curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
91
/* now specify which file to upload */
92
curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
94
/* and give the size of the upload (optional) */
95
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
98
/* Now run off and do what you've been told! */
99
res = curl_easy_perform(curl);
101
/* clean up the FTP commands list */
102
curl_slist_free_all (headerlist);
105
curl_easy_cleanup(curl);
107
fclose(hd_src); /* close the local file */
109
curl_global_cleanup();