master
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 "first.h"
26/*
27 * This example shows an FTP upload, with a rename of the file right after
28 * a successful upload.
29 *
30 * Example based on source code provided by Erick Nuwendam. Thanks!
31 */
33static CURLcode test_lib505(const char *URL)
34{
35 CURL *curl;
36 CURLcode result = CURLE_OK;
37 char errbuf[STRERROR_LEN];
38 FILE *hd_src;
39 int hd;
40 curlx_struct_stat file_info;
41 struct curl_slist *headerlist;
42 struct curl_slist *temp;
44 static const char buf_1[] = "RNFR 505";
45 static const char buf_2[] = "RNTO 505-forreal";
47 if(!libtest_arg2) {
48 curl_mfprintf(stderr, "Usage: <url> <file-to-upload>\n");
49 return TEST_ERR_USAGE;
50 }
52 hd_src = curlx_fopen(libtest_arg2, "rb");
53 if(!hd_src) {
54 curl_mfprintf(stderr, "fopen() failed with error (%d) %s\n",
55 errno, curlx_strerror(errno, errbuf, sizeof(errbuf)));
56 curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2);
57 return TEST_ERR_MAJOR_BAD; /* if this happens things are major weird */
58 }
60 /* get the file size of the local file */
61 hd = curlx_fstat(fileno(hd_src), &file_info);
62 if(hd == -1) {
63 /* cannot open file, bail out */
64 curl_mfprintf(stderr, "fstat() failed with error (%d) %s\n",
65 errno, curlx_strerror(errno, errbuf, sizeof(errbuf)));
66 curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2);
67 curlx_fclose(hd_src);
68 return TEST_ERR_MAJOR_BAD;
69 }
71 if(!file_info.st_size) {
72 curl_mfprintf(stderr, "File %s has zero size!\n", libtest_arg2);
73 curlx_fclose(hd_src);
74 return TEST_ERR_MAJOR_BAD;
75 }
77 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
78 curl_mfprintf(stderr, "curl_global_init() failed\n");
79 curlx_fclose(hd_src);
80 return TEST_ERR_MAJOR_BAD;
81 }
83 /* get a curl handle */
84 curl = curl_easy_init();
85 if(!curl) {
86 curl_mfprintf(stderr, "curl_easy_init() failed\n");
87 curl_global_cleanup();
88 curlx_fclose(hd_src);
89 return TEST_ERR_MAJOR_BAD;
90 }
92 /* build a list of commands to pass to libcurl */
94 headerlist = curl_slist_append(NULL, buf_1);
95 if(!headerlist) {
96 curl_mfprintf(stderr, "curl_slist_append() failed\n");
97 curl_easy_cleanup(curl);
98 curl_global_cleanup();
99 curlx_fclose(hd_src);
100 return TEST_ERR_MAJOR_BAD;
101 }
102 temp = curl_slist_append(headerlist, buf_2);
103 if(!temp) {
104 curl_mfprintf(stderr, "curl_slist_append() failed\n");
105 curl_slist_free_all(headerlist);
106 curl_easy_cleanup(curl);
107 curl_global_cleanup();
108 curlx_fclose(hd_src);
109 return TEST_ERR_MAJOR_BAD;
110 }
111 headerlist = temp;
113 /* enable uploading */
114 easy_setopt(curl, CURLOPT_UPLOAD, 1L);
116 /* enable verbose */
117 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
119 /* specify target */
120 easy_setopt(curl, CURLOPT_URL, URL);
122 /* pass in that last of FTP commands to run after the transfer */
123 easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
125 /* now specify which file to upload */
126 easy_setopt(curl, CURLOPT_READDATA, hd_src);
128 /* and give the size of the upload (optional) */
129 easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
131 /* Now run off and do what you have been told! */
132 result = curl_easy_perform(curl);
134test_cleanup:
136 /* clean up the FTP commands list */
137 curl_slist_free_all(headerlist);
139 /* close the local file */
140 curlx_fclose(hd_src);
142 curl_easy_cleanup(curl);
143 curl_global_cleanup();
145 return result;
146}
Diagnostics4 git calls · 58 ms
CallStatusSizeTime058 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit24 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=24 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2001.6 KiB · hit31 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=31 git.response.bytes=1669 git.response.cache=HIT git.response.duration_ms=31 git.fetch.wants=bf1310fcd2e686d1f147fd97a5b0817e11152ca6 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1669 git.pkt.payload.max=1648 git.sideband.band1.bytes=1647 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e31b57fb9a8682
- Request
- a4f2dc94…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format