Imported Upstream version 7.53.1
[platform/upstream/curl.git] / docs / examples / ftpuploadresume.c
index 1a24f7c..8f7f45d 100644 (file)
@@ -5,11 +5,11 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2015, 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
@@ -36,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
 
 
@@ -49,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;
@@ -67,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;
@@ -76,7 +77,7 @@ size_t readfunc(void *ptr, size_t size, size_t nmemb, void *stream)
 }
 
 
-int upload(CURL *curlhandle, const char * remotepath, const char * localpath,
+int upload(CURL *curlhandle, const char *remotepath, const char *localpath,
            long timeout, long tries)
 {
   FILE *f;
@@ -85,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;
   }
@@ -94,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);
@@ -105,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 */
 
       /*
@@ -127,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);
@@ -146,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));
@@ -161,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();