An FTP client.
// Create a new FTP client auto ftp = new Ftp(); // Connect to the server auto response = ftp.connect("ftp://ftp.myserver.com"); if (response.isOk()) writeln("Connected"); // Log in response = ftp.login("laurent", "dF6Zm89D"); if (response.isOk()) writeln("Logged in"); // Print the working directory auto directory = ftp.getWorkingDirectory(); if (directory.isOk()) writeln("Working directory: ", directory.getDirectory()); // Create a new directory response = ftp.createDirectory("files"); if (response.isOk()) writeln("Created new directory"); // Upload a file to this new directory response = ftp.upload("local-path/file.txt", "files", sf::Ftp::Ascii); if (response.isOk()) writeln("File uploaded"); // Send specific commands (here: FEAT to list supported FTP features) response = ftp.sendCommand("FEAT"); if (response.isOk()) writeln("Feature list:\n", response.getMessage()); // Disconnect from the server (optional) ftp.disconnect();
The $(U Ftp) class is a very simple FTP client that allows you to communicate with an 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:
$(PARA 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 `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.)