quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

ftp-delete.c (2411B)


      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      9  *
     10  * This software is licensed as described in the file COPYING, which
     11  * you should have received as part of this distribution. The terms
     12  * are also available at https://curl.se/docs/copyright.html.
     13  *
     14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
     15  * copies of the Software, and permit persons to whom the Software is
     16  * furnished to do so, under the terms of the COPYING file.
     17  *
     18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     19  * KIND, either express or implied.
     20  *
     21  * SPDX-License-Identifier: curl
     22  *
     23  ***************************************************************************/
     24 #include <stdio.h>
     25 
     26 #include <curl/curl.h>
     27 
     28 /* <DESC>
     29  * Delete a single file from an FTP server.
     30  * </DESC>
     31  */
     32 
     33 static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
     34 {
     35   (void)buffer;
     36   (void)stream;
     37   return size * nmemb;
     38 }
     39 
     40 
     41 int main(void)
     42 {
     43   CURL *curl;
     44   CURLcode res;
     45   struct curl_slist *headerlist = NULL;
     46 
     47   curl_global_init(CURL_GLOBAL_DEFAULT);
     48 
     49   curl = curl_easy_init();
     50   if(curl) {
     51     /*
     52      * You better replace the URL with one that works!
     53      */
     54     curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/");
     55     /* Define our callback to get called when there is data to be written */
     56     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
     57 
     58     /* Switch on full protocol/debug output */
     59     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
     60 
     61     /* build a list of commands to pass to libcurl */
     62     headerlist = curl_slist_append(headerlist, "DELE file-to-remove");
     63 
     64     /* pass in list of FTP commands to run after the transfer */
     65     curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
     66 
     67     res = curl_easy_perform(curl);
     68 
     69     /* always cleanup */
     70     curl_easy_cleanup(curl);
     71 
     72     /* clean up the FTP commands list */
     73     curl_slist_free_all(headerlist);
     74 
     75     if(CURLE_OK != res) {
     76       /* we failed */
     77       fprintf(stderr, "curl told us %d\n", res);
     78     }
     79   }
     80 
     81   curl_global_cleanup();
     82 
     83   return 0;
     84 }