Skip to content

Instantly share code, notes, and snippets.

@FabianFrank
Created January 19, 2014 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FabianFrank/8499412 to your computer and use it in GitHub Desktop.
Save FabianFrank/8499412 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <curl/curl.h>
int main (char** argv, int argc) {
CURL *curl;
CURLcode res;
char* url = NULL;
double filesize;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "sftp://localhost/Users/XXX/test.txt");
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
curl_easy_setopt(curl, CURLOPT_USERNAME, "XXX");
curl_easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, "XXX");
curl_easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, "XXX");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &filesize);
printf("URL: %s\n", url);
printf("FILESIZE: %0.0f\n", filesize);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment