Created
April 3, 2026 05:30
-
-
Save sunmeat/81124da90328b54cf56205b14fca6bd1 to your computer and use it in GitHub Desktop.
get file from hosting mac os version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| #include <curl/curl.h> | |
| using namespace std; | |
| size_t write_data(void* ptr, size_t size, size_t nmemb, FILE* stream) { | |
| return fwrite(ptr, size, nmemb, stream); | |
| } | |
| int main() | |
| { | |
| string srcURL = "http://sunmeat.atwebpages.com/volley/plain.txt"; | |
| string destFile = "/tmp/file.txt"; // macOS: /tmp замість C:/1/ | |
| CURL* curl = curl_easy_init(); | |
| if (!curl) { | |
| cerr << "Failed to init curl\n"; | |
| return 1; | |
| } | |
| FILE* f = fopen(destFile.c_str(), "wb"); | |
| if (!f) { | |
| cerr << "Cannot open file for writing\n"; | |
| curl_easy_cleanup(curl); | |
| return 1; | |
| } | |
| curl_easy_setopt(curl, CURLOPT_URL, srcURL.c_str()); | |
| curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); | |
| curl_easy_setopt(curl, CURLOPT_WRITEDATA, f); | |
| curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); | |
| CURLcode res = curl_easy_perform(curl); | |
| fclose(f); | |
| curl_easy_cleanup(curl); | |
| if (res == CURLE_OK) | |
| cout << "Saved to " << destFile << "\n"; | |
| else | |
| cout << "Fail! " << curl_easy_strerror(res) << "\n"; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment