curl-library
sftp
Date: Mon, 20 Sep 2010 15:43:33 +0000 (GMT)
Hi all,
I'm quite new to the world of C so I merely hacked this code together (it was
more a cut'n paste) ...
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
struct SftpFile
{
const char *filename;
FILE *stream;
};
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
{
struct SftpFile *out=(struct SftpFile *)stream;
if(out && !out->stream) {
/* open file for writing */
out->stream=fopen(out->filename, "wb");
if(!out->stream)
fprintf(stderr, "failure, can't open file to write");
return -1;
}
return fwrite(buffer, size, nmemb, out->stream);
}
int main(void)
{
CURL *curl;
CURLcode res;
struct SftpFile sftpfile={"core-n", /* name to store the file as if succesful
*/NULL};
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL,"sftp://192.168.0.1/~/tmp/core");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &sftpfile);
//curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PASSWORD);
curl_easy_setopt(curl, CURLOPT_USERPWD, "hlds:counter#12");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, 1);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if(CURLE_OK != res)
{
fprintf(stderr, "curl told us %d\n", res);
}
}
if(sftpfile.stream)
fclose(sftpfile.stream); /* close the local file */
return 0;
}
Basically the file should just get the corefile out of the /tmp direcxtory and
download it to my box via sftp (only ssh access is permitted)
The code compile without any complains, warnings or infos, but core-dumps when
executed.
From the dump I can see Error 58 ....
Any ideas ?
TIA
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-09-20