curl-library
Re: [curlpp-library] newbie questions
Date: Mon, 10 Jan 2005 13:35:42 -0500
On January 10, 2005 09:11 am, you wrote:
> Hello again,
>
> to be honest i still donīt get it. how does this help me to get the
> remote fileīs filesize?
>
Okay, here's the problem:
the SIZE FTP's command is not in the standard. But, anyway,
There's Thread in the mailing-list that discuss this matter:
http://curl.haxx.se/mail/lib-2004-09/0200.html
But if it doesn't answer your question, you should send your question
on the curl-library mailing-list (curl-library_at_cool.haxx.se). I'll be able to
answer your question on the C++ matter when you'll have your answer.
> max
>
> Jean-Philippe Barrette-LaPierre wrote:
> > Max Giesbert wrote:
> >> Salut Jean-Philippe,
> >>
> >> thx for your help. I really appreciate it.
> >>
> >> I am making an internship and it wasnī t my decision to use c++, but I
> >> learn a lot by using C++ even if it is sometimes hard for me to
> >> understand whatīs going on...
> >>
> >> If you put the example13 to CVS I can download it on monday (right
> >> know i canīt access the cvs repo). If not you can maybe mail it to me...
> >
> > here it is:
> >
> > =================
> >
> > #include <iostream>
> > #include <fstream>
> >
> > #include <curlpp/curlpp.hpp
> > #include <curlpp/ftp_easy.hpp>
> >
> >
> > /*
> > * This example shows an FTP upload, with a rename of the file just after
> > * a successful upload.
> > */
> >
> > #define UPLOAD_FILE_AS "example13-uploaded.txt"
> > #define RENAME_FILE_TO "example13-renamed.txt"
> >
> > int main(int argc, char **argv)
> > {
> > if(argc != 3) {
> > std::cerr << "example02: Arguments missing." << std::endl;
> > std::cerr << "example02: Usage: example18 remote_url localfile" <<
> > std::endl;
> > return EXIT_FAILURE;
> > }
> >
> > char *local_file = argv[1];
> > char *remote_url = argv[2];
> >
> > // Get the file size of the local file (optional)
> > // It seem to be the more standard C++ way to do it.
> > // Open the file at the end of the file (ios::ate),
> > // and return the read position (tellg)
> > std::ifstream hd_src(local_file, std::ios::in | std::ios::ate);
> > if(!hd_src) {
> > std::cerr << "example13: Could not open the local file." << std::endl;
> > return EXIT_FAILURE;
> > }
> > std::ios::pos_type hd_src_len = hd_src.tellg();
> >
> > // Rewinds the reading pos to the beginning.
> > hd_src.seekg(0, std::ios::beg);
> >
> > // Now we build our request.
> > try {
> > // You will be sure that curlpp::initialize and
> > // curlpp::terminate will be called.
> > curlpp::cleanup myCleanup;
> >
> > // This is our request object.
> > curlpp::ftp_easy request;
> >
> > /* build a list of commands to pass to libcurl */
> > std::list< std::string > headerlist;
> > headerlist.push_back("RNFR " UPLOAD_FILE_AS);
> > headerlist.push_back("RNTO " RENAME_FILE_TO);
> >
> > /* enable uploading */
> > request.upload();
> >
> > /* specify target */
> > request.url(remote_url);
> >
> > /* pass in that last of FTP commands to run after the transfer */
> > request.post_quote(headerlist);
> >
> > /* now specify which file to upload */
> > curlpp::istream_trait my_trait(&hd_src);
> > request.m_input_storage.trait(&my_trait, false);
> >
> > /* and give the size of the upload (optional) */
> > request.infile_size(hd_src_len);
> >
> > /* Now run off and do what you've been told! */
> > request.perform();
> > }
> > catch(curlpp::exception &e) {
> > std::cerr << e.what() << std::endl;
> > return EXIT_FAILURE;
> > }
> >
> > return EXIT_SUCCESS;
> > }
> >
> >
> > =================
> >
> >> Merci beaucoup
> >>
> >> Max
> >>
> >> Jean-Philippe Barrette-LaPierre wrote:
> >>> Max Giesbert wrote:
> >>>> hallo again,
> >>>>
> >>>> as i havenīt heard anything so far i will try to concretise my aims.
> >>>> sorry if my questions sound naive but i am very new to c++ but need
> >>>> this to work...
> >>>
> >>> Sorry, I've been very busy trying to release the version 0.3.2 and
> >>> 0.5.0 (not yet released).
> >>>
> >>>> i have a program that copies local files as well as smb files (via
> >>>> libsmbclient) in a manner where i have my functions like
> >>>> "my_fileHandle->write(char* buffer, int charsToWrite)". so when the
> >>>> function finishes i know that charsToWrite chars were written from
> >>>> my buffer to the handles destination. and vice versa for the read
> >>>> function.
> >>>>
> >>>> now i wanted to integrate ftp functionality using curlpp. but
> >>>> everything seems quite weird to me... (as i told you i am new to
> >>>> C++ and know even less about pure C...)
> >>>>
> >>>> i would to implement something like this:
> >>>>
> >>>> //contents of Ftp.h
> >>>> #ifndef FTP_H
> >>>> #define FTP_H
> >>>>
> >>>> #include <curlpp/easy.hpp>
> >>>>
> >>>> class Ftp{
> >>>> public:
> >>>>
> >>>> Ftp();
> >>>> {
> >>>> ftpHandle_ = new curlpp::easy;
> >>>> }
> >>>> Ftp(std::string url) : url_(url)
> >>>> {
> >>>> ftpHandle_ = new curlpp::easy;
> >>>> ftpHandle_->url(url_);
> >>>> }
> >>>> virtual ~Ftp() { delete *ftpHandle_; }
> >>>> void open(std::string url) { ftpHandle_->url(url_); }
> >>>> bool exists();
> >>>> long file_size();
> >>>> void read(char *buffer, int charsToRead);
> >>>> void write(char *buffer, int charsToWrite);
> >>>>
> >>>> private:
> >>>> std::string url_;
> >>>> curlpp::easy *ftpHandle_;
> >>>> };
> >>>>
> >>>> #endif // FTP_H
> >>>>
> >>>> what do you think about this. does it make sense? i really need some
> >>>> hints in implementing these functions. i appreciate your help very
> >>>> much.
> >>>
> >>> I made you a complete example. This example will be included in the
> >>> next release
> >>> as the example 13. Maybe I didn't simplified the example as more as
> >>> possible,
> >>> but that's the better way to do it in C++.
> >>> If you need more help don't hesitate to ask, even if it's only C++
> >>> related. Btw,
> >>> why are you using C++? No offense, but it seem that you don't have a
> >>> good knowledge
> >>> of it, so why did you choose this language?
> >>>
> >>>> thanks
> >>>>
> >>>> max
> >>>>
> >>>> Max Giesbert wrote:
> >>>>> hallo everyone,
> >>>>>
> >>>>> I just started using curlpp and I am quite stuck. so far I have 2
> >>>>> questions:
> >>>>>
> >>>>> 1. how do I get the filesize of a file lying on a ftp-server. I
> >>>>> read some libcurl stuff about the "NO_BODY" option and a "SIZE"
> >>>>> command but I canīt figure out how this is going to work.
> >>>>>
> >>>>> 2. I would like to do reading/writing to/from an URL in a typical
> >>>>> c++ style with a read/write function like this: void read(char
> >>>>> *mybuffer, int charsToRead) . So far I reimplemented the
> >>>>> input_trait class like this: (but I think I am on the wrong way)
> >>>>>
> >>>>> class ftpRead : public curlpp::input_trait
> >>>>> {
> >>>>> public:
> >>>>> virtual ~ftpRead(){}
> >>>>>
> >>>>> ftpRead(char *my_buffer) : my_buffer_(my_buffer) {}
> >>>>> size_t read( void *curlpp_buffer, size_t length )
> >>>>> {
> >>>>> char *buffer = static_cast< char * >( curlpp_buffer );
> >>>>> for(unsigned int i = 0; i < length; i++)
> >>>>> {
> >>>>> my_buffer_[i] = buffer[i];
> >>>>> }
> >>>>> return length;
> >>>>> }
> >>>>> private:
> >>>>> char *my_buffer_;
> >>>>> };
> >>>>>
> >>>>> what do think about the idea of a layer/interface that gives the
> >>>>> same function like standard c++ file/stream handling?
> >>>>>
> >>>>> thx for your help
> >>>>>
> >>>>> max
> >>>>>
> >>>>>
> >>>>> -------------------------------------------------------
> >>>>> The SF.Net email is sponsored by: Beat the post-holiday blues
> >>>>> Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
> >>>>> It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
> >>>>> _______________________________________________
> >>>>> curlpp-library mailing list
> >>>>> curlpp-library_at_lists.sourceforge.net
> >>>>> https://lists.sourceforge.net/lists/listinfo/curlpp-library
> >>>>
> >>>> -------------------------------------------------------
> >>>> The SF.Net email is sponsored by: Beat the post-holiday blues
> >>>> Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
> >>>> It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
> >>>> _______________________________________________
> >>>> curlpp-library mailing list
> >>>> curlpp-library_at_lists.sourceforge.net
> >>>> https://lists.sourceforge.net/lists/listinfo/curlpp-library
-- Jean-Philippe Barrette-LaPierre Maintener of cURLpp (http://rrette.com/curlpp)Received on 2005-01-10