curl-library
Fwd: Unable to copy files to windows shared drive using libCurl and FILE protocol
Date: Fri, 4 Jan 2019 22:18:16 +0530
On Fri, Jan 4, 2019 at 5:36 AM Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Thu, 3 Jan 2019, Krishna Chaithanya B via curl-library wrote:
>
> > I am using the curl-7.62.0 built for VC17 X64 machine to develop a file
> > uploader utility. The file uploader uploads the file to a network drive.
>
> ...
>
> > Now I want to achieve the same programmatically and I am writing my
> > component in C++.
>
> ...
>
> > The control never goes to the callback method at all and hence the upload
> > never happens. Does CURL support the FILE Protocol ?
>
> How would the command line tool work if it didn't?
>
>
> > I can see the examples of FTPUpload, HTTPupload but there are no
> examples
> > with the FILE protocol on Windows.
>
> 1. set CURLOPT_VERBOSE to 1L first to see if it tells you anything
> interesting
>
> 2. check/print the return code from curl_easy_perform() as it is probably
> useful
>
I am seeing CURLE_WRITE_ERROR as return code, so I tried to add a
writeCallback but still there is no use.
Here is my updated code.
> int Uploader::upload(const std::string& url)
>
> {
> CURLcode res;
> FILE *hd_src;
> struct stat file_info;
> curl_off_t fsize;
>
>
> /* get the file size of the local file */
> if (stat(LOCAL_FILE, &file_info)) {
> printf("Couldnt open '%s': %s\n", LOCAL_FILE, strerror(errno));
> return -1;
> }
> fsize = (curl_off_t)file_info.st_size;
>
> printf("Local file size: %" CURL_FORMAT_CURL_OFF_T " bytes.\n", fsize);
>
> /* get a FILE * of the same file */
> hd_src = fopen(LOCAL_FILE, "rb");
>
> /* In windows, this will init the winsock stuff */
> curl_global_init(CURL_GLOBAL_ALL);
>
> /* get a curl handle */
> curl_ = curl_easy_init();
> if (curl_) {
> /* enable uploading */
> curl_easy_setopt(curl_, CURLOPT_UPLOAD, 1L);
>
> /* specify target */
> curl_easy_setopt(curl_, CURLOPT_URL, url.c_str());
>
> fprintf(stderr, "CURLOPT_URL: %s\n", url.c_str());
>
> /* we want to use our own read function */
> curl_easy_setopt(curl_, CURLOPT_READFUNCTION, read_callback);
>
> std::string response_string;
> curl_easy_setopt(curl_, CURLOPT_WRITEDATA, &response_string);
> curl_easy_setopt(curl_, CURLOPT_WRITEFUNCTION, write_callback);
>
> curl_easy_setopt(curl_, CURLOPT_VERBOSE, 1L);
>
> /* now specify which file to upload */
> curl_easy_setopt(curl_, CURLOPT_READDATA, hd_src);
>
> /* Set the size of the file to upload (optional). If you give a
> *_LARGE
> option you MUST make sure that the type of the passed-in
> argument is a
> curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you
> must
> make sure that to pass in a type 'long' argument. */
> curl_easy_setopt(curl_, CURLOPT_INFILESIZE_LARGE,
> (curl_off_t)fsize);
>
> /* Now run off and do what you've been told! */
> res = curl_easy_perform(curl_);
>
> printf("Response string: %s\n", response_string.c_str());
>
> if (res != CURLE_OK)
> fprintf(stderr, "curl_easy_perform() failed: %s\n",
> curl_easy_strerror(res));
> }
>
> fclose(hd_src); /* close the local file */
>
> return 0;
> }
>
>
> > Am I doing it right?
>
> The URL you're working with looks weird:
> "file:////<ip_address>/ShareDrive/"
>
> The format is "file://[host]/path" and the only [host] that curl accepts
> is
> one of "" (nothing), "localhost" or "127.0.0.1". The file:// URL format
> doesn't really specify how to connect to another host.
>
> The [host] that I am planning to use is not localhost. It is a shared
network drive.
But, I tried to use the localhost like you suggested and I still see the
same error:
CURLE_WRITE_ERROR as result of the curl_perform.
Local file size: 11 bytes.
CURLOPT_URL: file://localhost/Share_Softwares/
* Can't open \Share_Softwares\ for writing
* Closing connection 0
Response string:
curl_easy_perform() failed: Failed writing received data to disk/application
> Sorry for the lengthy email, I am really stuck on this for a week now.
>
What am trying to achieve here was to copy the local files to a remote
shared network drive.
I am able to do that using Windows API but I read CuRL will be faster and
so I wanted to
explore curl, but am stuck due to these errors, and I am not getting any
help on StackOverflow
as well, so my only hope is to reach-out to you and learn what am doing
wrong here.
Thank you.
> --
>
> / daniel.haxx.se
>
-- Regards, Krishna Chaithanya B -- Regards, Krishna Chaithanya B
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-01-04