#include "test.h"
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
int test(char *URL)
{
CURL *curl;
CURLcode res;
FILE *hd_src ;
int hd ;
struct stat file_info;
struct curl_slist *headerlist=NULL;
const char *buf_1 = "RNFR 505";
const char *buf_2 = "RNTO 505-forreal";
hd = stat(arg2, &file_info);
if(hd == -1) {
return -1;
}
if(! file_info.st_size) {
fprintf(stderr, "WARNING: file %s has no size!\n", arg2);
return -4;
}
hd_src = fopen(arg2, "rb");
if(NULL == hd_src) {
return -2;
}
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
struct curl_slist *hl;
hl = curl_slist_append(headerlist, buf_1);
if(hl) {
headerlist = curl_slist_append(hl, buf_2);
if(hl)
headerlist = hl;
}
curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE) ;
curl_easy_setopt(curl,CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_info.st_size);
res = curl_easy_perform(curl);
curl_slist_free_all (headerlist);
curl_easy_cleanup(curl);
}
fclose(hd_src);
curl_global_cleanup();
return res;
}