FC++  v0.7.2-1115
FileCatalyst Fast File Transfers - C++ Library
Example C++ Source Code

Example C++ source code:

#include <FileCatalyst.hpp>
void example( const std::string &serverIpOrHostname, const std::string &username, const std::string &password )
{
// Set a few options needed by fc::Control so it knows how to behave.
fc::Options options;
options.setFtpServer( serverIpOrHostname, 21 );
options.setUsernameAndPassword( username, password );
options.setMd5Verification( true );
options.setMode( fc::kUdp );
// Create the FTP fc::Control object. Once it is created, the
// fc::Options object is no longer required and can go out-of-scope.
fc::Control ftp( options );
// Connect to the server with the options originally provided by
// fc::Options. If connect() is not explicitly called, then the
// connection is deferred until a method is called which needs to
// communicate directly with the server.
ftp.connect();
// Note that even after a connection has been established, many (but
// not all) FTP settings can still be modified.
fc::Options newOptions = ftp.getOptions();
newOptions.setBandwidth( fc::k100_Mbps );
ftp.setNewOptions( newOptions );
// Download some files from the server.
ftp.prepareRecursiveDir( fc::Remote("/project"), fc::Local("/tmp") );
ftp.download();
...

The FC++ API will throw a C++ exception if a problem is detected, so there is no need to perform error checking after every call. The only exception object thrown from the FC++ API is fc::Exception which inherits from std::exception.

Additional example files:

File Description
example001.cpp Getting started with fc::Control and fc::Options. This includes several simple tasks such as directory listings using fc::Control::getDirectoryListing() and MD5 checksums with fc::Control::getFileMD5(). Does not show how to transfer a file.
example002.cpp Download a single file with fc::Control::download() and uses fc::Control::getMostRecentFileStats() to display a large number of statistics on the file itself as well as the UDP transfer.
example003.cpp Very simple example of uploading a file using fc::Control::upload().
example004.cpp Use a 2nd thread combined with fc::Control::getMostRecentFileStats() to display a simple progress indicator while the original thread completes a download using fc::Control::prepareSingleFile() and fc::Control::download().
example005.cpp Retrieve a fc::FDVec (std::vector of fc::FileDetails) and display information on all the files on the remote server.
example006.cpp Use fc::Control::prepareRecursiveDir() to download a set of file and subdirectories, then upload the same set to a new location. Statistics on all the transferred files are displayed using fc::TransferStats::getStr().
example007.cpp Use the callback hook fc::Control::setStatsCallback() to get a statistics callback every second during a transfer.