मैं एफ़टीपी का उपयोग कर फ़ाइल डाउनलोड करने की कोशिश कर रहा हूं, और कनेक्शन के समाप्त होने के बीच में इसे फिर से शुरू करना चाहिए जहां से यह रुक गया था। मेरी समस्या यह है कि निम्न कोड स्निपेट का उपयोग करके मैं डाउनलोड जारी रखने में सक्षम हूं अगर मैं कनेक्शन बंद करता हूं और फिर इसे कनेक्ट करता हूं, लेकिन अगर मैं सर्वर साइट पर ऐसा कर रहा हूं तो मैं डाउनलोड फिर से शुरू करने में सक्षम नहीं हूं, और प्रोग्राम infinites स्थिति में चला जाता है।सीएल में कर्ल का उपयोग करके एफ़टीपी के माध्यम से फ़ाइल डाउनलोड कैसे शुरू करें?
#include <stdio.h>
#include <curl/curl.h>
/*
* This is an example showing how to get a single file from an FTP server.
* It delays the actual destination file creation until the first write
* callback so that it won't create an empty file in case the remote file
* doesn't exist or something else fails.
*/
struct FtpFile {
const char *filename;
FILE *stream;
};
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 main(void)
{
CURL *curl;
CURLcode res;
struct FtpFile ftpfile={
"dev.zip", /* name to store the file as if succesful */
NULL
};
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
/*
* You better replace the URL with one that works!
*/
curl_easy_setopt(curl, CURLOPT_URL,
"ftp://root:[email protected]/dev.zip");
/* Define our callback to get called when there's data to be written */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
/* Set a pointer to our struct to pass to the callback */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
/* Switch on full protocol/debug output */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
if(CURLE_OK != res) {
/* we failed */
fprintf(stderr, "curl told us %d\n", res);
}
}
if(ftpfile.stream)
fclose(ftpfile.stream); /* close the local file */
curl_global_cleanup();
return 0;
}
क्या कोई मुझे बता सकता है कि रिमोट साइट द्वारा कनेक्शन बंद होने पर मैं फिर से डाउनलोड कैसे कर सकता हूं। किसी भी मदद की सराहना की जाएगी
धन्यवाद,
युवी
क्या कुछ चीज http की 'AddRange' ftp में है? –
हाँ यह वहां है लेकिन मेरी समस्या यह है कि कनेक्शन बंद होने पर मैं त्रुटि पकड़ने में सक्षम नहीं हूं, और अधिक जानने के लिए आप इसे यहां देख सकते हैं http://curl.haxx.se/libcurl/c/ftpuploadresume.html – Yuvi