Hi,

I want to establish the FTP connection from machine A to machine B using 
LibCurl and want to transfer the file (*.txt) from B to A. After the 
successful transmission of file  (*.txt) from B to A, delete the file 
which is available on Machine B.

Please find the code that I have written for doing the same is in the 
attached file.


After the execution of executable, I am getting the error which is in the 
attached file.



Please help me to solve the problem.


Regards,

Amol Raoji Madane
Tata Consultancy Services
DLF Akruti Info Park,
PN 28,
Rajiv Gandhi Infotech Park   Hinjewadi, PHASE II
Pune - 411057,Maharashtra
India
Ph:- +91-20-6675-2352
Buzz:- 420-2352
Mailto: [email protected]
Website: http://www.tcs.com
____________________________________________
Experience certainty.   IT Services
                        Business Solutions
                        Outsourcing
____________________________________________



From:
Daniel Stenberg <[email protected]>
To:
Amol Madane <[email protected]>
Cc:
libcurl hacking <[email protected]>
Date:
04/19/2010 03:10 PM
Subject:
Re: Establish the FTP Connection and file Transfer from on location to 
other



On Mon, 19 Apr 2010, Amol Madane wrote:

> I am writing a FTP script to sit on a server which basically needs to 
> connect to another remote server and read the file and return them as a 
> file.

So you need to get a file with FTP using libcurl. Can you tell us more 
specificly what parts of the docs and examples you don't understand?

-- 

  / daniel.haxx.se


=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you


#include <stdio.h>
#include <unistd.h>
#include <curl.h>
#include <cstdlib>
#include <iostream>
#define UPLOAD_FILE_AS  "11.txt"

int main(int argc, char **argv)
{
        int return_global_init;
        CURL *curl;
        static const char buf_1 [] = "RETR " UPLOAD_FILE_AS;
        static const char buf_2 [] = "PORT ";// "PORT " "172,29,59,199,244,142";

        //CURLcode res;
        return_global_init=curl_global_init(CURL_GLOBAL_ALL);
  
        /*struct curl_slist *slist=NULL;
        slist = curl_slist_append(slist, "MKDIR test");*/
        
                struct curl_slist* commands = NULL ;
        // struct curl_slist* commands1 = NULL ;
        
        commands = curl_slist_append( commands , buf_1 ) ;
        commands = curl_slist_append( commands , buf_2 ) ;
        
        if (return_global_init==0)
        {
                curl = curl_easy_init();
                if (curl)
                {
                        curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
                        std::cout << "Error No - 1" << curl_easy_setopt (curl, 
CURLOPT_URL, "ftp://172.29.59.216/";)<< std::endl;
                        std::cout << "Error No - 2" << curl_easy_setopt (curl, 
CURLOPT_VERBOSE, 1)<< std::endl;
                        std::cout << "Error No - 3" << curl_easy_setopt (curl, 
CURLOPT_USERNAME , "gaurav")<< std::endl;
                        std::cout << "Error No - 4" << curl_easy_setopt (curl, 
CURLOPT_PASSWORD ,"gaurav")<< std::endl; 
                        std::cout << "Error No - 5" <<curl_easy_setopt(curl, 
CURLOPT_POSTQUOTE, commands)<< std::endl;
                        
                                    
                        /*  std::cout << "Error No - 1" << curl_easy_setopt 
(curl, CURLOPT_URL, "ftp://172.29.59.199/";)<< std::endl;
                        std::cout << "Error No - 2" << curl_easy_setopt (curl, 
CURLOPT_VERBOSE, 1)<< std::endl;
                        std::cout << "Error No - 3" << curl_easy_setopt (curl, 
CURLOPT_USERNAME , "Amol")<< std::endl;
                        std::cout << "Error No - 4" << curl_easy_setopt (curl, 
CURLOPT_PASSWORD ,"Amol")<< std::endl; 
                        std::cout << "Error No - 5" <<curl_easy_setopt(curl, 
CURLOPT_QUOTE, commands1)<< std::endl; */
                        //curl_easy_setopt (curl, CURLOPT_FTP_USE_EPRT, 0); 
                        
                        curl_easy_perform(curl);
                        
                        // curl_easy_setopt(curl, CURLOPT_POSTQUOTE, slist); 
                }
        }
}
# ./FTPMGet_g
Error No - 10
Error No - 20
Error No - 30
Error No - 40
Error No - 50
* About to connect() to 172.29.59.216 port 21 (#0)
*   Trying 172.29.59.216... * connected
* Connected to 172.29.59.216 (172.29.59.216) port 21 (#0)
< 220 172.29.59.216 FTP server (QNXNTO-ftpd 20070723) ready.
> USER gaurav
< 331 Password required for gaurav.
> PASS gaurav
< 230-
<     Welcome to QNX Neutrino!
< 230 User gaurav logged in.
> PWD
< 257 "/home/gaurav" is the current directory.
* Entry path is '/home/gaurav'
* Uploading to a URL without a file name!
* Closing connection #0
* URL using bad/illegal format or missing URL
#
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to