FC++  v0.9.0-9e9b65
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.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.
fc::Options::setMode
virtual Options & setMode(const fc::ETransferMode tm=fc::kUdp, const fc::EConnectionMode cm=fc::kPassive)
Set the FTP mode.
Definition: FCOptions.cpp:356
fc::Options::setFtpServer
virtual Options & setFtpServer(const std::string &ip_or_hostname, const unsigned short tcp_port=21)
Set the FTP server address and port.
Definition: FCOptions.cpp:303
fc::Options::setUsernameAndPassword
virtual Options & setUsernameAndPassword(const std::string &username, const std::string &password)
Set the username and password to use when connecting to the FTP server.
Definition: FCOptions.cpp:347
fc::Options
fc::Options contains all the default and user-defined settings required by fc::Control to connect to ...
Definition: FCOptions.hpp:282
fc::k100_Mbps
@ k100_Mbps
100000000 bps
Definition: FCOptions.hpp:140
fc::Remote
The class fc::Remote is used to encapsulate remote directories or files.
Definition: FCPath.hpp:160
password
const std::string password
Definition: example001.cpp:20
username
const std::string username
Definition: example001.cpp:19
fc::Options::setMd5Verification
virtual Options & setMd5Verification(const bool enabled=false, const int mode=0)
Toggle MD5 verification.
Definition: FCOptions.cpp:525
fc::Options::setBandwidth
virtual Options & setBandwidth(const uint64_t full_bandwidth_bps=fc::bps(fc::kZero_bps), const uint64_t slow_start_bandwidth_bps=fc::bps(fc::kZero_bps))
Set the maximum and initial transfer rates which will be requested from the FileCatalyst server.
Definition: FCOptions.cpp:440
fc::Local
The class fc::Local is used to encapsulate local directories or files.
Definition: FCPath.hpp:141
fc::kUdp
@ kUdp
2 UDP (FileCatalyst mode)
Definition: FCOptions.hpp:51
FileCatalyst.hpp
fc::Control
Definition: FCControl.hpp:52