Traversing the server's contents

ftp->chdir("/pub");

std::set<std::string> directory;

ftp->list(std::insert_iterator<std::vector<std::string>>(dir, dir.end());

ftp->cdup();

std::string pwd=ftp->pwd();

std::string result=ftp->site("chmod 755 file.dat");

Use chdir() and cdup() to navigate the server's directory structure. list() obtains a human-readable listing of the server's directory. The first parameter is an output iterator. Each line in the listing gets written to the output iterator. The remaining, optional parameters to list():

  1. The directory name. This returns a listing of the specified directory's contents, instead of the current directory.

  2. x::fdtimeoutconfig that sets up the timeout configuration for the data channel used to transfer the requested data.

nlst() works exactly like list() but the server returns just the name of each file in the server's directory, on each line, and nothing else.

pwd() returns the name of the current directory, and site() executes some arbitrary server-specific command.

x::ymdhms timestamp=ftp->timestamp("filename");
off64_t filesize=ftp->size("filename");

std::map<std::string, x::ftp::client::base::stat> stat;

ftp->filestat([&stat]
    (const char *filename, const x::ftp::client::base::stat &info)
    {
        stat[filename]=info;
    }, "filename");

ftp->dirstat([&stat]
    (const char *filename, const x::ftp::client::base::stat &info)
    {
        stat[filename]=info;
    }, "directory");

timestamp() returns the modification file of some file on the server, and size() gives the file's size, where available. Some older servers may not implement the newer FTP commands, used by filestat() and dirstat() methods.

filestat() returns file information about a single file (this is the MLST command described in RFC 3659) dirstat() returns information about every file in a given directory (this would be MLSD). Both methods take a lambda or a functor as their first argument, which receives two parameters: the file's name, and a x::ftp::client::base::stat for that file or directory entry. Normally filestat()'s callback usually gets called once, and dirstat()'s callback gets called once for each file in a directory, but some servers might make additional calls for each file, for the reasons described in RFC 3659.