curl-users
CURl 56 : Failure when receiving data from the peer
Date: Wed, 16 Sep 2009 14:19:04 +0530 (IST)
hello,
i am trying to download ~500 MB of data from remote machine using SFTP.
I am getting Error code 56 with error string "failure when receiving data from the peer".
Following code works fine when tried to download data from local machine.
please have a look at following code snippet and let me know if something is wrong.
CODE snippet :
int cmdGetFile (const char *username, const char *password,
const char *hostip,
const char *srcFile,
const char *destFile, int resumeFlag,
int largeFile /* =0 */)
{
CURL *curl = NULL;
CURLcode res = CURLE_OK;
/* get the file size of the local file */
struct stat file_info;
if (stat (destFile, &file_info) == -1) {
file_info.st_size = 0;
}
struct FtpFile ftpfile;
ftpfile.filename = destFile;
ftpfile.stream = NULL;
curl_global_init (CURL_GLOBAL_ALL);
curl = curl_easy_init ();
if (curl) {
string url = string ("sftp://") + hostip + srcFile;
string userpwd = username + string (":") + password;
curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, my_fwrite);
curl_easy_setopt (curl, CURLOPT_WRITEDATA, &ftpfile);
curl_easy_setopt (curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt (curl, CURLOPT_USERPWD, userpwd.c_str ());
curl_easy_setopt (curl, CURLOPT_FTP_RESPONSE_TIMEOUT, 2100L);
if (resumeFlag == 1) {
curl_easy_setopt (curl, (largeFile) ? CURLOPT_RESUME_FROM_LARGE : CURLOPT_RESUME_FROM,file_info.st_size);
}
/* Now run off and do what you've been told! */
res = curl_easy_perform (curl);
/* always cleanup */
curl_easy_cleanup (curl);
}
if(ftpfile.stream)
fclose(ftpfile.stream); /* close the local file */
curl_global_cleanup ();
return int(res);
}
static size_t my_fwrite (void *buffer, size_t size, size_t nmemb, void *stream)
{
struct FtpFile *out = (struct FtpFile *) stream;
if (out && !out->stream) {
/* open file for writing */
out->stream = fopen (out->filename, "wb");
if (!out->stream) {
return (-1); /* failure, can't open file to write */
}
}
return (fwrite (buffer, size, nmemb, out->stream));
}
Thanks,
Rajashri Bhor.
Yahoo! India has a new look. Take a sneak peek http://in.yahoo.com/trynew
-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-09-16