curl-library
RE: Reg:FTP upload in libcurl
Date: Fri, 20 Jun 2008 10:37:45 +0530
Hi
Platfrom:Linux
Technology:C++
In Connect I wont be providing the file name it is just for Connection
But the UploadFile I sent the file name from another applciaiton
Now is it enough that I just give the filename in the "" or should I
specify the URL also .
Because I am reusing the connection from Connect just need to do a file
transfer via this call
curl_easy_setopt(curl,CURLOPT_URL,"/tmp/test")
Deos the above work if the connection is already made like below
I create a object of type FTP_TEST
FTP_TEST ob1;
Ob1.Connect()-->This is working fine.
Ob1.Uploadfile_FTP (localpath,remotepath);
In Uploadfile_FTP I am Re-Using the Connection.Now I want to send the
file
Regards
Nagarajan
-----Original Message-----
From: curl-library-bounces_at_cool.haxx.se
[mailto:curl-library-bounces_at_cool.haxx.se
<mailto:curl-library-bounces_at_cool.haxx.se> ] On Behalf Of Dan Fandrich
Sent: Friday, June 20, 2008 9:54 AM
To: curl-library_at_cool.haxx.se
Subject: Re: Reg:FTP upload in libcurl
On Fri, Jun 20, 2008 at 09:12:56AM +0530,
nagarajan.sreenivasan_at_wipro.com wrote:
> Connect()
> {
> char * REMOTE_URL=new char[100];
> strcpy(REMOTE_URL,"ftp:// <ftp://> ");
>
> strncat(REMOTE_URL,userName,strlen(userName));
> strcat(REMOTE_URL,":");
> strncat(REMOTE_URL,passWord,strlen(passWord));
> strcat(REMOTE_URL,"@");
> strncat(REMOTE_URL,hostName,strlen(hostName));
You're not providing a file name here in the URL. The remote server has
no way to know what to call the file without it, so this will cause an
error.
Also, what's the point of using strncat here? By providing a length
equal to the string to concatenate, the function becomes identical to
strcat.
You really want to use strlcat here instead if you're worried about
buffer overflows.
>
> CurlInternalSettings();
> curl_easy_setopt(curl,CURLOPT_URL,REMOTE_URL);
> res = curl_easy_perform(curl);
> }
>
> void CurlInternalSettings()
> {
> curl_global_init(CURL_GLOBAL_ALL);
>
> curl = curl_easy_init();
> if(curl) {
> curl_easy_setopt(curl,CURLOPT_VERBOSE,1);
>
> }
>
> UploadFile_FTP(remoetpath,local path)
> {
>
> FILE *hd_src;
> struct stat file_info;
>
> char *UPLOAD_FILE_AS=new char[255];
>
> strncpy(UPLOAD_FILE_AS,remotePathName,strlen(remotePathName));
This string isn't actually used anywhere.
>
> struct curl_slist *headerlist=NULL;
>
> char *buf_1=new char [255];
>
> if(curl) {
> headerlist = curl_slist_append(headerlist, buf_1);
> // headerlist = curl_slist_append(headerlist, buf_2);
> curl_easy_setopt(curl,CURLOPT_VERBOSE,1);
> // curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
> // curl_easy_setopt(curl, CURLOPT_INFILE,&file_info);
> curl_easy_setopt(curl, CURLOPT_UPLOAD,1);
> curl_easy_setopt(curl, CURLOPT_INFILESIZE,
> (curl_off_t)file_info.st_size);
>
> curl_easy_setopt(curl,CURLOPT_URL,);------------------------------->wh
> at should this line be () or is there any other way i can send my file
As mentioned above, this URL needs to include the file name of the
remote file.
> curl_easy_setopt(curl, CURLOPT_PREQUOTE, headerlist);
> curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
hd_src isn't opened anywhere. You need to call fopen() on it to provide
some data to send. I've forgotten what platform you're using, but this
won't always work for Windows.
> res = curl_easy_perform(curl);
> }
>>> Dan
-- http://www.MoveAnnouncer.com <http://www.MoveAnnouncer.com> The web change of address service Let webmasters know that your web site has moved Please do not print this email unless it is absolutely necessary. The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.comReceived on 2008-06-20