summaryrefslogtreecommitdiff
path: root/docs/examples/ftpuploadresume.c
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/ftpuploadresume.c')
-rw-r--r--docs/examples/ftpuploadresume.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c
index 55b8986c7..641563404 100644
--- a/docs/examples/ftpuploadresume.c
+++ b/docs/examples/ftpuploadresume.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
- * are also available at http://curl.haxx.se/docs/copyright.html.
+ * are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
@@ -19,13 +19,9 @@
* KIND, either express or implied.
*
***************************************************************************/
-/* Upload to FTP, resuming failed transfers
- *
- * Compile for MinGW like this:
- * gcc -Wall -pedantic -std=c99 ftpuploadwithresume.c -o ftpuploadresume.exe
- * -lcurl -lmsvcr70
- *
- * Written by Philip Bock
+/* <DESC>
+ * Upload to FTP, resuming failed transfers.
+ * </DESC>
*/
#include <stdlib.h>
@@ -40,7 +36,8 @@
/* The MinGW headers are missing a few Win32 function definitions,
you shouldn't need this if you use VC++ */
#if defined(__MINGW32__) && !defined(__MINGW64__)
-int __cdecl _snscanf(const char * input, size_t length, const char * format, ...);
+int __cdecl _snscanf(const char * input, size_t length,
+ const char * format, ...);
#endif
@@ -53,7 +50,7 @@ size_t getcontentlengthfunc(void *ptr, size_t size, size_t nmemb, void *stream)
/* _snscanf() is Win32 specific */
r = _snscanf(ptr, size * nmemb, "Content-Length: %ld\n", &len);
- if (r) /* Microsoft: we don't read the specs */
+ if(r) /* Microsoft: we don't read the specs */
*((long *) stream) = len;
return size * nmemb;
@@ -71,7 +68,7 @@ size_t readfunc(void *ptr, size_t size, size_t nmemb, void *stream)
FILE *f = stream;
size_t n;
- if (ferror(f))
+ if(ferror(f))
return CURL_READFUNC_ABORT;
n = fread(ptr, size, nmemb, f) * size;
@@ -89,7 +86,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath,
int c;
f = fopen(localpath, "rb");
- if (f == NULL) {
+ if(!f) {
perror(NULL);
return 0;
}
@@ -98,7 +95,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath,
curl_easy_setopt(curlhandle, CURLOPT_URL, remotepath);
- if (timeout)
+ if(timeout)
curl_easy_setopt(curlhandle, CURLOPT_FTP_RESPONSE_TIMEOUT, timeout);
curl_easy_setopt(curlhandle, CURLOPT_HEADERFUNCTION, getcontentlengthfunc);
@@ -109,14 +106,15 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath,
curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc);
curl_easy_setopt(curlhandle, CURLOPT_READDATA, f);
- curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-"); /* disable passive mode */
+ /* disable passive mode */
+ curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-");
curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1L);
- for (c = 0; (r != CURLE_OK) && (c < tries); c++) {
+ for(c = 0; (r != CURLE_OK) && (c < tries); c++) {
/* are we resuming? */
- if (c) { /* yes */
+ if(c) { /* yes */
/* determine the length of the file already written */
/*
@@ -131,7 +129,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath,
curl_easy_setopt(curlhandle, CURLOPT_HEADER, 1L);
r = curl_easy_perform(curlhandle);
- if (r != CURLE_OK)
+ if(r != CURLE_OK)
continue;
curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 0L);
@@ -150,7 +148,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath,
fclose(f);
- if (r == CURLE_OK)
+ if(r == CURLE_OK)
return 1;
else {
fprintf(stderr, "%s\n", curl_easy_strerror(r));
@@ -165,7 +163,8 @@ int main(int c, char **argv)
curl_global_init(CURL_GLOBAL_ALL);
curlhandle = curl_easy_init();
- upload(curlhandle, "ftp://user:pass@example.com/path/file", "C:\\file", 0, 3);
+ upload(curlhandle, "ftp://user:pass@example.com/path/file", "C:\\file",
+ 0, 3);
curl_easy_cleanup(curlhandle);
curl_global_cleanup();