Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2012
    Location
    Huntington Beach, CA
    Posts
    3

    Ftp Help, But A Little More Than That

    I am attempting to write some C++ 11 code from C# 5.0 code that I have already written. I am new to C++.

    The main purpose of the C# code that I wrote was:
    1. to make a connection with an ftp server
    2. access the servers file directory
    3. select a file in that director
    4. download the file to the local directory
    5. reduce the local file string to substrings
    6. write those substirngs to the local directory in json format.

    So the first wall I’ve hit is how do you connect to a ftp server with c++? In my C# code I used the System.Net.WebRequest. So I went to msdn and looked at the c++ documentation for the WebRequest Class. But then a thought hit me, *this is the c# way of doing things. I want to do things the C++ way.

    So the first question is, how should I go about connecting to a ftp server the C++ way?

    The second question is, am I thinking about this the right way?

    I’ve ran around the web looking at things, but I am now more confused than if I was going to do this the C# way. Microsoft has a C++ REST SDK. But is that not the C# way. Maybe I’m such a newb that I may need to depend on this library, but isn’t the point of C++ for you to build the things you need. As a newb should I not start building things, then once I have a good understanding use others libraries.


    The c# code works point to point. For those who are members, I based my ftp fetch off the async webRequest from windows phone 8 training by nelson.

    I know this is a long question, and I’m making this longer. However, I think this question goes deeper than the question of how do I implement a ftp web request, and I thank anyone who takes the time to answer this question sincerely.

  2. #2
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    There are a few things that you should realize first:

    • C++ is not very good at web-based programming compared to other languages. It downright sucks at small-scale web applications like the one you described. This is mainly due to lack of library support and not an inherent flaw of the language though. If I had the choice I would never implement something like this in C++, simply because the result would be unnecessarily complicated and would not make use of any of the features where C++ excels. I would consider C++ the wrong tool for the job, at least if your goal is to get things done (as opposed to learn how things work).
    • FTP is an outdated and quirky technology that does not get much love these days. It does not work well with modern network infrastructures (NAT anyone?) and scores very poorly when it comes to security. If it's your choice to make, you should switch to one of the more modern protocols instead (that would probably mean HTTPS or SFTP for now; do not use FTPS, it's just FTP with an SSL layer on top; and please don't start with WebDAV, it's even worse than FTP )


    Your options from here on out are limited and depend largely on what you are trying to achieve:
    • There's a couple of C libraries which provide FTP support to varying degrees (libcurl, ftplib, ...). I never used any of them, so I can't tell you much here. There is however no clear one lib to rule them all here, which already is a strong indicator to how little people care for FTP these days.
    • From the big C++ libraries, Qt and Poco have FTP support. Both are large frameworks so pulling them in for just this one feature is questionable. Casablanca (aka MS REST SDK) is, as the name suggests, HTTP only, so it's not a choice here (although it's otherwise a very interesting library; your fear that it might C#-ify your code is baseless).
    • There are a few minor C++ libraries that offer FTP support but none of them seems to be widely used. Again, the love for FTP is small. In particular I could not find a single library that supports the full ftp featureset and is portable to the big three, Windows, Linux and OS X (although I must say I did not look very hard).
    • Use a network library and write your own FTP implementation. This is the worst piece of advice if you want to write production-quality code, as it takes much more time than using an ftp library and it's very likely that your implementation will be buggy at first. However, it might be the best approach if your goal is to learn how things work. The best way to learn about the inner workings of a protocol is still to implement it yourself.
      The network library of choice for C++ at the moment is Boost Asio. It provides a thin but very powerful abstraction of plain BSD sockets and encourages efficient, modern C++ code.


    So, unfortunately not the best of options for now, but I hope this post helps you anyway.

  3. #3
    Join Date
    Mar 2012
    Location
    Huntington Beach, CA
    Posts
    3
    Thank you very much. I'll take your advice and use the c# async methods to go out and get the documents from the ftp server. Unfortunately, the content I'm attempting to retrieve from the ftp server is not within my control, it is on an out dated system, but the content is worth the trouble.

    I do appreciate for the most part that I'm trying to move a coffee table by pushing it with a diesel train. But how does one learn without coding, and I did not know where to go after the C++ 102 course to continue the process of coding in C++.

    So any advice on where to go from here with the process of learning c++ would also be greatly appreciated.

  4. #4
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    Quote Originally Posted by 5thStone View Post
    So any advice on where to go from here with the process of learning c++ would also be greatly appreciated.
    Herb Sutter did an interesting challenge at GoingNative this year: He asked developers to pick up a C++ multimedia library that they never used before and see what they could do with it overnight. Granted, these were already all C++ professionals but it is still astounding what they could come up with after just a few hours of work.

    Among the libraries used here were Cinder, openframeworks and SFML.
    This is actually a fantastic model for learning new stuff: Set yourself a strict timeframe (like a single weekend), pick up a library that looks interesting and see what you can do. This is essentially the same model that drives gamejams and it works remarkably well in getting your creative juices flowing. I'd highly recommend to try this out if you don't know what to do next.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •