1
1
/*****************************************************************************
3
* Project ___| | | | _ \| |
5
* | (__| |_| | _ <| |___
3
* Project ___| | | | _ \| |
5
* | (__| |_| | _ <| |___
6
6
* \___|\___/|_| \_\_____|
8
* $Id: ftp3rdparty.c,v 1.1 2004/06/03 11:15:27 bagder Exp $
8
* $Id: ftp3rdparty.c,v 1.2 2005/01/21 09:32:33 bagder Exp $
18
18
* This is an example showing how to transfer a file between two remote hosts.
19
* 7.13.0 or later required.
27
char sourceFileName[] = "/tmp/file";
28
char targetFileName[] = "/tmp/curlTargetTest.dat";
29
char sourceHost[] = "source";
30
char targetHost[] = "target";
26
char source_url[] = "ftp://remotehost.com/path/to/source";
27
char target_url[] = "ftp://aotherserver.com/path/to/dest";
31
29
char sourceUserPass[] = "user:pass";
32
30
char targetUserPass[] = "user:pass";
35
33
struct curl_slist *source_pre_cmd = NULL;
36
34
struct curl_slist *target_pre_cmd = NULL;
37
35
struct curl_slist *source_post_cmd = NULL;
39
37
char cmd[] = "PWD"; /* just to test */
41
39
curl_global_init(CURL_GLOBAL_DEFAULT);
43
41
curl = curl_easy_init();
45
sprintf(url, "ftp://%s@%s/%s", targetUserPass, targetHost, targetFileName);
47
curl_easy_setopt(curl, CURLOPT_URL, url);
49
/* Set a proxy host */
50
curl_easy_setopt(curl, CURLOPT_SOURCE_HOST, sourceHost);
52
/* Set a proxy user and password */
43
/* The ordinary URL is the target when speaking 3rd party transfers */
44
curl_easy_setopt(curl, CURLOPT_URL, target_url);
46
/* Set a source URL */
47
curl_easy_setopt(curl, CURLOPT_SOURCE_URL, source_url);
49
/* Set target user and password */
50
curl_easy_setopt(curl, CURLOPT_USERPWD, targetUserPass);
52
/* Set source user and password */
53
53
curl_easy_setopt(curl, CURLOPT_SOURCE_USERPWD, sourceUserPass);
55
/* Set a proxy full file name */
56
curl_easy_setopt(curl, CURLOPT_SOURCE_PATH, sourceFileName);
58
/* Set a proxy passive host */
59
curl_easy_setopt(curl, CURLOPT_PASV_HOST, 0); /* optional */
56
/* FTPPORT enables PORT on the target side, instead of PASV. */
57
curl_easy_setopt(curl, CURLOPT_FTPPORT, ""); /* optional */
61
60
/* build a list of commands to pass to libcurl */
62
61
source_pre_cmd = curl_slist_append(source_pre_cmd, cmd);
77
76
target_post_cmd = curl_slist_append(target_post_cmd, cmd);
78
77
/* Set a post-quote command */
79
78
curl_easy_setopt(curl, CURLOPT_POSTQUOTE, target_post_cmd);
81
80
/* Switch on full protocol/debug output */
82
81
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);