Using cmd to transfer files via ftp - c++

I was reading about this and found out most people use libcurl as the c++ library to use ftp, but I know windows has a built-in ftp client, isn't it possible to use that instead? I mean, it would also save a lot of space, even if you are just sending commands to the cmd, it could be done, but why does nobody do this? Is it like lazy programming or something? like akin to using goto?

If you need to up/download lots of files, handle errors, do progress etc then it's easier to use a library. If you simply need to pull a file from a remote server then the commandline tool is easier.
The windows ftp client can run a sequence of commands after logging in, but if you need this extra level of complexity it might be easier to use a library.

Related

Tab completion over ssh library

I am using paramiko library to connect with a specialized environment. Its based on linux but when we SSH in it provide its own shell. We can write help to get list of all commands that are supported in that session.
I am using paramiko with python2.7 to provide a CLI client (it automates few things) that connect with the host and let us run the supported commands. Now I would like to provide tab-completion in the client CLI. I am not sure how this can be done. I am thinking there would be some support or some specialize character that can be send to get back response but I am not sure how it can be accomplished.
I am hoping to avoid sending help command, parse the list of commands supported, and then provide a local tab-completion based on list of command. I want a more generic and dynamic solution.
Any or all ideas are welcome.
You can try simulating the partial input and the Tab key press and parsing the results, undoing the simulated input afterwards. But that is not a good idea. You will have to end up re-implementing terminal emulation, what is an insane task. Without a full terminal implementation, you can never be sure that you never get an output that you won't be able to parse.
The shell is a black box with input and output. It should only be used as such. You should never try to "understand" its output.
Using the help command is a way more reliable solution.

Simple cross-platform settings manager

I'm writing a cross-platform game (in C++) called Bombz and I need a way to read/write users' settings etc, which will also include records of which levels have been completed. Something like an ini file parser will be fine, and it doesn't really need to be efficient and/or scaleable - I can read all the settings at start-up instead of looking up named keys on the fly.
I've found a few simple ini file parsers but they overlook the question of where to store the files and it looks like I might have to write all this stuff myself. Should I just use something like:
Windows: $APPDATA/realh/Bombz/config
Mac: $HOME/Library/Bombz/config
Linux etc: $HOME/.bombz/config (or use the XDG spec)
where I look up $HOME or $APPDATA with getenv()? I know there are "better approved" ways of looking that up in Windows but I'm a Linux guy and I don't want to have to deal with the Windows API directly.
Well, it's quite interesting -- someone trying to write a game without calling OS-functions. Quite a challenge.
Other than that, if you don't want to call SHGetKnownFolderPath() then environment variables are your only bet. Although for myself, I don't even trust $HOME on Linux -- I use getpwuid_r(). And NSHomeDirectory() on MacOS.

Saving a webpage to disk using C++

I've managed to download a "file" from the internet with the help of wininet library, but I can't seem to save a "webpage" i.e. something I can edit later on with a text editor or with ifstream.
In this case, what are the tools I should resort to? Can wininet save a webpage to disk? Should I consider cURL (though I haven't managed to download regular files due to lack of documentation of cURL)? Do I need to learn what's called socket programming?
NB: I'm on Windows, using MinGW but can switch to MSVC if necessary, I'm looking for source code in the webpage, eventually I'm after the text in a webpage.
Also, I am not familiar with any of the functions in wininet, curl, or sockets. What do I need to learn of these?
Any help is greatly appreciated!
If your program is going to run both on windows and unix, then use cURL. Otherwise, stick with MSVC and WinINet functions http://msdn.microsoft.com/en-us/library/windows/desktop/aa385473(v=vs.85).aspx It's much easier to use in terms of the efforts required to get your program running and distributed (esp. if you're not linking your program against cUrl statically. Otherwise, you'll need to take libcurl.dll everywhere your program runs on Windows). With WinINet, you simply need to include a header and a library to use the functions.
If you're going to use WinINet, refer to this code snippet: http://www.programmershelp.co.uk/showcode.php?e=57
Use the same code except for the while loop. Instead of reading one byte at a time, read them by chunks and write them to the output file handle.
If you're going to use cURL, refer to this post: Download file using libcurl in C/C++

Simple interactive prompt in C++

I work on an application that usually runs unattended. Now I need to add to it something like an interactive prompt. In the interactive mode the operator will be able to give simple commands to the application - nothing fancy, simple commands like start and stop. Parametrized commands (e.g. repeat 10) and commands history could be nice too.
Do you know, by chance, any library that helps with such tasks. I've been thinking about something that works like boost::program_options or gflags but for an interactive prompt and not for command line parameters. Any ideas?
Thanks
Readline is one the best known libraries for this
http://tiswww.case.edu/php/chet/readline/rltop.html
It is covered by GPL, so it is only possible to use in GPL-compatible programs.
I did a quick search for alternatives, and found this:
http://github.com/antirez/linenoise
I'm not sure if the following is a reasonable amount of work for what you're trying to do, but Python has a very nice Command Line Interface (CLI) building library called cmd2. If it's possible to expose the relevant parts of your apps to Python using SWIG or CTypes, then doing the rest should be easy.
Here's a nice video presentation about cmd2:
PyCon 2010:Easy command-line applications with cmd and cmd2
HTH
One possibilty is to open a TCP port and accept messages in text format. Then you can telnet to that port and issue simple commands.

How to send files b/w two machines through socket programming?

I have requirement to send all the files in the directory to a different machines, the directory may internally contain child directories.
Is there any help available on this?
One more doubt is: I also heard that we can send the files using FTP, if so which is the best between the two. Is there any help available for this?
I need to implement this on windows platform using vc++/c++
Thanks
One possibility is the TransmitFile() function in the windows API. You'll have to traverse the directories to find individual files with your own code.
You should probably combine and compress the files/directories on the source end.
Transmit and unbundle on the other end.
A library to help (that is free) is bzip (http://www.bzip.org/)
You should be able to do everything in memory if you do it well but potentially you can also use intermediate files.
Sounds like a homework problem.
FTP uses sockets internally.
Make an initial try at the problem and post it here. You'll get more help if people think you are trying, rather than just freeloading.