An FTP client.
1 // Create a new FTP client 2 auto ftp = new Ftp(); 3 4 // Connect to the server 5 auto response = ftp.connect("ftp://ftp.myserver.com"); 6 if (response.isOk()) 7 writeln("Connected"); 8 9 // Log in 10 response = ftp.login("laurent", "dF6Zm89D"); 11 if (response.isOk()) 12 writeln("Logged in"); 13 14 // Print the working directory 15 auto directory = ftp.getWorkingDirectory(); 16 if (directory.isOk()) 17 writeln("Working directory: ", directory.getDirectory()); 18 19 // Create a new directory 20 response = ftp.createDirectory("files"); 21 if (response.isOk()) 22 writeln("Created new directory"); 23 24 // Upload a file to this new directory 25 response = ftp.upload("local-path/file.txt", "files", sf::Ftp::Ascii); 26 if (response.isOk()) 27 writeln("File uploaded"); 28 29 // Send specific commands (here: FEAT to list supported FTP features) 30 response = ftp.sendCommand("FEAT"); 31 if (response.isOk()) 32 writeln("Feature list:\n", response.getMessage()); 33 34 // Disconnect from the server (optional) 35 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.)