cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-users Mailing List Archives

Re: unable to download zip files completely using SFTP.

From: rajashri bhor <rajashri_bhor_at_yahoo.com>
Date: Tue, 10 Mar 2009 10:49:10 +0530 (IST)

>>>> Could the problem be end of line character differences in the files? If you're sending binary data, it doesn't make sense to set CURLOPT_TRANSFERTEXT to 1. [rajashri] its a ASCII data (plain text file). Thanks, Rajashri Bhor. ________________________________ From: rajashri bhor <rajashri_bhor@yahoo.com> To: curl-users@cool.haxx.se Sent: Tuesday, 10 March, 2009 10:23:03 AM Subject: unable to download zip files completely using SFTP. hello, i have written a code to download compressed (.zip) files using SFTP. It seems that zip file is not downloading complete file. size of source file and destination file is different. source file size is : 5103167 bytes downloaded file size is : 5095424 bytes difference in size is : 7743 bytes. after download if i try to gunzip the downloaded file i get following error : gunzip: <filename>.gz: unexpected end of file code snippet : 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)); } int cmdGetFile (LoggerPtr loggerCxx, 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) { EMS_LOG (loggerCxx, "Couldnt open '" << destFile << "': " << strerror (errno) << " resuming download from start") file_info.st_size = 0; } else { EMS_LOG ( loggerCxx, "Resuming download of '" << destFile << "': " << " from " << file_info.st_size) } 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_TRANSFERTEXT, 1); 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 ()); 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); EMS_LOG (loggerCxx, "Curl returned: (" << res << ") " << curl_easy_strerror (res)) /* always cleanup */ curl_easy_cleanup (curl); } curl_global_cleanup (); return int(res); } int main(int argc, char **argv) { cmdGetFile("userName", "password", "10.4.7.22", "sourcefile.gz", "destfile.gz", 0, 0); return 0; } I am compiling above code on solaris platform. CURL version : 7.19.0 (SFTP enabled) LIBSSH2 version : 1.0 OPENSSL version : 0.9.7g Thanks, Rajashri Bhor. ________________________________ Add more friends to your messenger and enjoy! Invite them now. ________________________________ Add more friends to your messenger and enjoy! Invite them now. Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/

-------------------------------------------------------------------
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-03-10

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET