|
| Ftp ()=default |
| Default constructor.
|
| ~Ftp () |
| Destructor.
|
| Ftp (const Ftp &)=delete |
| Deleted copy constructor.
|
Ftp & | operator= (const Ftp &)=delete |
| Deleted copy assignment.
|
Response | connect (IpAddress server, unsigned short port=21, Time timeout=Time::Zero) |
| Connect to the specified FTP server.
|
Response | disconnect () |
| Close the connection with the server.
|
Response | login () |
| Log in using an anonymous account.
|
Response | login (const std::string &name, const std::string &password) |
| Log in using a username and a password.
|
Response | keepAlive () |
| Send a null command to keep the connection alive.
|
DirectoryResponse | getWorkingDirectory () |
| Get the current working directory.
|
ListingResponse | getDirectoryListing (const std::string &directory="") |
| Get the contents of the given directory.
|
Response | changeDirectory (const std::string &directory) |
| Change the current working directory.
|
Response | parentDirectory () |
| Go to the parent directory of the current one.
|
Response | createDirectory (const std::string &name) |
| Create a new directory.
|
Response | deleteDirectory (const std::string &name) |
| Remove an existing directory.
|
Response | renameFile (const std::filesystem::path &file, const std::filesystem::path &newName) |
| Rename an existing file.
|
Response | deleteFile (const std::filesystem::path &name) |
| Remove an existing file.
|
Response | download (const std::filesystem::path &remoteFile, const std::filesystem::path &localPath, TransferMode mode=TransferMode::Binary) |
| Download a file from the server.
|
Response | upload (const std::filesystem::path &localFile, const std::filesystem::path &remotePath, TransferMode mode=TransferMode::Binary, bool append=false) |
| Upload a file to the server.
|
Response | sendCommand (const std::string &command, const std::string ¶meter="") |
| Send a command to the FTP server.
|
A FTP client.
sf::Ftp is a very simple FTP client that allows you to communicate with a FTP server.
The FTP protocol allows you to manipulate a remote file system (list files, upload, download, create, remove, ...).
Using the FTP client consists of 4 parts:
- Connecting to the FTP server
- Logging in (either as a registered user or anonymously)
- Sending commands to the server
- Disconnecting (this part can be done implicitly by the destructor)
Every command returns a FTP response, which contains the status code as well as a message from the server. Some commands such as getWorkingDirectory() and getDirectoryListing() return additional data, and use a class derived from sf::Ftp::Response to provide this data. The most often used commands are directly provided as member functions, but it is also possible to use specific commands with the sendCommand() function.
Note that response statuses >= 1000 are not part of the FTP standard, they are generated by SFML when an internal error occurs.
All commands, especially upload and download, may take some time to complete. This is important to know if you don't want to block your application while the server is completing the task.
Usage example:
std::cout << "Connected" << std::endl;
response = ftp.
login(
"laurent",
"dF6Zm89D");
std::cout << "Logged in" << std::endl;
std::cout <<
"Working directory: " << directory.
getDirectory() << std::endl;
std::cout << "Created new directory" << std::endl;
std::cout << "File uploaded" << std::endl;
std::cout <<
"Feature list:\n" << response.
getMessage() << std::endl;
Specialization of FTP response returning a directory.
const std::filesystem::path & getDirectory() const
Get the directory returned in the response.
bool isOk() const
Check if the status code means a success.
const std::string & getMessage() const
Get the full message contained in the response.
@ Ascii
Text mode using ASCII encoding.
Response createDirectory(const std::string &name)
Create a new directory.
Response sendCommand(const std::string &command, const std::string ¶meter="")
Send a command to the FTP server.
Response connect(IpAddress server, unsigned short port=21, Time timeout=Time::Zero)
Connect to the specified FTP server.
Response login()
Log in using an anonymous account.
DirectoryResponse getWorkingDirectory()
Get the current working directory.
Response disconnect()
Close the connection with the server.
Response upload(const std::filesystem::path &localFile, const std::filesystem::path &remotePath, TransferMode mode=TransferMode::Binary, bool append=false)
Upload a file to the server.
Definition at line 49 of file Ftp.hpp.