SFML - Simple and Fast Multimedia Library

SFML 3.0.1

- Main Page
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

Loading...
Searching...
No Matches
Ftp.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2025 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
30#include <SFML/Network/Export.hpp>
31
32#include <SFML/Network/TcpSocket.hpp>
33
34#include <SFML/System/Time.hpp>
35
36#include <filesystem>
37#include <string>
38#include <vector>
39
40
41namespace sf
42{
43class IpAddress;
44
49 class SFML_NETWORK_API Ftp
50{
51public:
56 enum class TransferMode
57 {
58 Binary,
59 Ascii,
60 Ebcdic
61 };
62
67 class SFML_NETWORK_API Response
68 {
69 public:
74 enum class Status
75 {
76 // 1xx: the requested action is being initiated,
77 // expect another reply before proceeding with a new command
78 RestartMarkerReply = 110,
79 ServiceReadySoon = 120,
80 DataConnectionAlreadyOpened = 125,
81 OpeningDataConnection = 150,
82
83 // 2xx: the requested action has been successfully completed
84 Ok = 200,
85 PointlessCommand = 202,
86 SystemStatus = 211,
87 DirectoryStatus = 212,
88 FileStatus = 213,
89 HelpMessage = 214,
90 SystemType = 215,
91 ServiceReady = 220,
92 ClosingConnection = 221,
93 DataConnectionOpened = 225,
94 ClosingDataConnection = 226,
95 EnteringPassiveMode = 227,
96 LoggedIn = 230,
97 FileActionOk = 250,
98 DirectoryOk = 257,
99
100 // 3xx: the command has been accepted, but the requested action
101 // is dormant, pending receipt of further information
102 NeedPassword = 331,
103 NeedAccountToLogIn = 332,
104 NeedInformation = 350,
105
106 // 4xx: the command was not accepted and the requested action did not take place,
107 // but the error condition is temporary and the action may be requested again
108 ServiceUnavailable = 421,
109 DataConnectionUnavailable = 425,
110 TransferAborted = 426,
111 FileActionAborted = 450,
112 LocalError = 451,
113 InsufficientStorageSpace = 452,
114
115 // 5xx: the command was not accepted and
116 // the requested action did not take place
117 CommandUnknown = 500,
118 ParametersUnknown = 501,
119 CommandNotImplemented = 502,
120 BadCommandSequence = 503,
121 ParameterNotImplemented = 504,
122 NotLoggedIn = 530,
123 NeedAccountToStore = 532,
124 FileUnavailable = 550,
125 PageTypeUnknown = 551,
126 NotEnoughMemory = 552,
127 FilenameNotAllowed = 553,
128
129 // 10xx: SFML custom codes
130 InvalidResponse = 1000,
131 ConnectionFailed = 1001,
132 ConnectionClosed = 1002,
133 InvalidFile = 1003
134 };
135
146 explicit Response(Status code = Status::InvalidResponse, std::string message = "");
147
157 [[nodiscard]] bool isOk() const;
158
165 [[nodiscard]] Status getStatus() const;
166
173 [[nodiscard]] const std::string& getMessage() const;
174
175 private:
177 // Member data
179 Status m_status;
180 std::string m_message;
181 };
182
187 class SFML_NETWORK_API DirectoryResponse : public Response
188 {
189 public:
196 DirectoryResponse(const Response& response);
197
204 [[nodiscard]] const std::filesystem::path& getDirectory() const;
205
206 private:
208 // Member data
210 std::filesystem::path m_directory;
211 };
212
213
218 class SFML_NETWORK_API ListingResponse : public Response
219 {
220 public:
228 ListingResponse(const Response& response, const std::string& data);
229
236 [[nodiscard]] const std::vector<std::string>& getListing() const;
237
238 private:
240 // Member data
242 std::vector<std::string> m_listing;
243 };
244
249 Ftp() = default;
250
258 ~Ftp();
259
264 Ftp(const Ftp&) = delete;
265
270 Ftp& operator=(const Ftp&) = delete;
271
293 [[nodiscard]] Response connect(IpAddress server, unsigned short port = 21, Time timeout = Time::Zero);
294
303 [[nodiscard]] Response disconnect();
304
314 [[nodiscard]] Response login();
315
328 [[nodiscard]] Response login(const std::string& name, const std::string& password);
329
339 [[nodiscard]] Response keepAlive();
340
352 [[nodiscard]] DirectoryResponse getWorkingDirectory();
353
369 [[nodiscard]] ListingResponse getDirectoryListing(const std::string& directory = "");
370
383 [[nodiscard]] Response changeDirectory(const std::string& directory);
384
393 [[nodiscard]] Response parentDirectory();
394
408 [[nodiscard]] Response createDirectory(const std::string& name);
409
425 [[nodiscard]] Response deleteDirectory(const std::string& name);
426
441 [[nodiscard]] Response renameFile(const std::filesystem::path& file, const std::filesystem::path& newName);
442
458 [[nodiscard]] Response deleteFile(const std::filesystem::path& name);
459
480 [[nodiscard]] Response download(const std::filesystem::path& remoteFile,
481 const std::filesystem::path& localPath,
482 TransferMode mode = TransferMode::Binary);
483
505 [[nodiscard]] Response upload(const std::filesystem::path& localFile,
506 const std::filesystem::path& remotePath,
507 TransferMode mode = TransferMode::Binary,
508 bool append = false);
509
526 [[nodiscard]] Response sendCommand(const std::string& command, const std::string& parameter = "");
527
528private:
538 Response getResponse();
539
545 class DataChannel;
546
547 friend class DataChannel;
548
550 // Member data
552 TcpSocket m_commandSocket;
553 std::string m_receiveBuffer;
554};
555
556} // namespace sf
557
558
Export.hpp
SFML_NETWORK_API
#define SFML_NETWORK_API
Definition Network/Export.hpp:42
TcpSocket.hpp
Time.hpp
sf::Ftp::DirectoryResponse
Specialization of FTP response returning a directory.
Definition Ftp.hpp:188
sf::Ftp::DirectoryResponse::DirectoryResponse
DirectoryResponse(const Response &response)
Default constructor.
sf::Ftp::DirectoryResponse::getDirectory
const std::filesystem::path & getDirectory() const
Get the directory returned in the response.
sf::Ftp::ListingResponse
Specialization of FTP response returning a file name listing.
Definition Ftp.hpp:219
sf::Ftp::ListingResponse::getListing
const std::vector< std::string > & getListing() const
Return the array of directory/file names.
sf::Ftp::ListingResponse::ListingResponse
ListingResponse(const Response &response, const std::string &data)
Default constructor.
sf::Ftp::Response
FTP response.
Definition Ftp.hpp:68
sf::Ftp::Response::isOk
bool isOk() const
Check if the status code means a success.
sf::Ftp::Response::getStatus
Status getStatus() const
Get the status code of the response.
sf::Ftp::Response::Response
Response(Status code=Status::InvalidResponse, std::string message="")
Default constructor.
sf::Ftp::Response::getMessage
const std::string & getMessage() const
Get the full message contained in the response.
sf::Ftp::Response::Status
Status
Status codes possibly returned by a FTP response.
Definition Ftp.hpp:75
sf::Ftp::Response::Status::SystemStatus
@ SystemStatus
System status, or system help reply.
Definition Ftp.hpp:86
sf::Ftp::Response::Status::DataConnectionUnavailable
@ DataConnectionUnavailable
Can't open data connection.
Definition Ftp.hpp:109
sf::Ftp::Response::Status::NotEnoughMemory
@ NotEnoughMemory
Requested file action aborted, exceeded storage allocation.
Definition Ftp.hpp:126
sf::Ftp::Response::Status::CommandNotImplemented
@ CommandNotImplemented
Command not implemented.
Definition Ftp.hpp:119
sf::Ftp::Response::Status::FileStatus
@ FileStatus
File status.
Definition Ftp.hpp:88
sf::Ftp::Response::Status::ClosingConnection
@ ClosingConnection
Service closing control connection.
Definition Ftp.hpp:92
sf::Ftp::Response::Status::ServiceUnavailable
@ ServiceUnavailable
Service not available, closing control connection.
Definition Ftp.hpp:108
sf::Ftp::Response::Status::HelpMessage
@ HelpMessage
Help message.
Definition Ftp.hpp:89
sf::Ftp::Response::Status::ConnectionClosed
@ ConnectionClosed
Not part of the FTP standard, generated by SFML when the low-level socket connection is unexpectedly ...
Definition Ftp.hpp:132
sf::Ftp::Response::Status::ServiceReadySoon
@ ServiceReadySoon
Service ready in N minutes.
Definition Ftp.hpp:79
sf::Ftp::Response::Status::InvalidResponse
@ InvalidResponse
Not part of the FTP standard, generated by SFML when a received response cannot be parsed.
Definition Ftp.hpp:130
sf::Ftp::Response::Status::ParameterNotImplemented
@ ParameterNotImplemented
Command not implemented for that parameter.
Definition Ftp.hpp:121
sf::Ftp::Response::Status::NeedAccountToStore
@ NeedAccountToStore
Need account for storing files.
Definition Ftp.hpp:123
sf::Ftp::Response::Status::SystemType
@ SystemType
NAME system type, where NAME is an official system name from the list in the Assigned Numbers documen...
Definition Ftp.hpp:90
sf::Ftp::Response::Status::CommandUnknown
@ CommandUnknown
Syntax error, command unrecognized.
Definition Ftp.hpp:117
sf::Ftp::Response::Status::FileUnavailable
@ FileUnavailable
Requested action not taken, file unavailable.
Definition Ftp.hpp:124
sf::Ftp::Response::Status::DirectoryStatus
@ DirectoryStatus
Directory status.
Definition Ftp.hpp:87
sf::Ftp::Response::Status::PageTypeUnknown
@ PageTypeUnknown
Requested action aborted, page type unknown.
Definition Ftp.hpp:125
sf::Ftp::Response::Status::NotLoggedIn
@ NotLoggedIn
Not logged in.
Definition Ftp.hpp:122
sf::Ftp::Response::Status::ParametersUnknown
@ ParametersUnknown
Syntax error in parameters or arguments.
Definition Ftp.hpp:118
sf::Ftp::Response::Status::NeedPassword
@ NeedPassword
User name ok, need password.
Definition Ftp.hpp:102
sf::Ftp::Response::Status::DataConnectionAlreadyOpened
@ DataConnectionAlreadyOpened
Data connection already opened, transfer starting.
Definition Ftp.hpp:80
sf::Ftp::Response::Status::TransferAborted
@ TransferAborted
Connection closed, transfer aborted.
Definition Ftp.hpp:110
sf::Ftp::Response::Status::Ok
@ Ok
Command ok.
Definition Ftp.hpp:84
sf::Ftp::Response::Status::LocalError
@ LocalError
Requested action aborted, local error in processing.
Definition Ftp.hpp:112
sf::Ftp::Response::Status::BadCommandSequence
@ BadCommandSequence
Bad sequence of commands.
Definition Ftp.hpp:120
sf::Ftp::Response::Status::ClosingDataConnection
@ ClosingDataConnection
Closing data connection, requested file action successful.
Definition Ftp.hpp:94
sf::Ftp::Response::Status::ConnectionFailed
@ ConnectionFailed
Not part of the FTP standard, generated by SFML when the low-level socket connection with the server ...
Definition Ftp.hpp:131
sf::Ftp::Response::Status::DataConnectionOpened
@ DataConnectionOpened
Data connection open, no transfer in progress.
Definition Ftp.hpp:93
sf::Ftp::Response::Status::InvalidFile
@ InvalidFile
Not part of the FTP standard, generated by SFML when a local file cannot be read or written.
Definition Ftp.hpp:133
sf::Ftp::Response::Status::RestartMarkerReply
@ RestartMarkerReply
Restart marker reply.
Definition Ftp.hpp:78
sf::Ftp::Response::Status::EnteringPassiveMode
@ EnteringPassiveMode
Entering passive mode.
Definition Ftp.hpp:95
sf::Ftp::Response::Status::InsufficientStorageSpace
@ InsufficientStorageSpace
Requested action not taken; insufficient storage space in system, file unavailable.
Definition Ftp.hpp:113
sf::Ftp::Response::Status::ServiceReady
@ ServiceReady
Service ready for new user.
Definition Ftp.hpp:91
sf::Ftp::Response::Status::FileActionAborted
@ FileActionAborted
Requested file action not taken.
Definition Ftp.hpp:111
sf::Ftp::Response::Status::PointlessCommand
@ PointlessCommand
Command not implemented.
Definition Ftp.hpp:85
sf::Ftp::Response::Status::DirectoryOk
@ DirectoryOk
PATHNAME created.
Definition Ftp.hpp:98
sf::Ftp::Response::Status::NeedInformation
@ NeedInformation
Requested file action pending further information.
Definition Ftp.hpp:104
sf::Ftp::Response::Status::FilenameNotAllowed
@ FilenameNotAllowed
Requested action not taken, file name not allowed.
Definition Ftp.hpp:127
sf::Ftp::Response::Status::OpeningDataConnection
@ OpeningDataConnection
File status ok, about to open data connection.
Definition Ftp.hpp:81
sf::Ftp::Response::Status::NeedAccountToLogIn
@ NeedAccountToLogIn
Need account for login.
Definition Ftp.hpp:103
sf::Ftp::Response::Status::FileActionOk
@ FileActionOk
Requested file action ok.
Definition Ftp.hpp:97
sf::Ftp::Response::Status::LoggedIn
@ LoggedIn
User logged in, proceed. Logged out if appropriate.
Definition Ftp.hpp:96
sf::Ftp::TransferMode
TransferMode
Enumeration of transfer modes.
Definition Ftp.hpp:57
sf::Ftp::TransferMode::Binary
@ Binary
Binary mode (file is transferred as a sequence of bytes)
Definition Ftp.hpp:58
sf::Ftp::TransferMode::Ascii
@ Ascii
Text mode using ASCII encoding.
Definition Ftp.hpp:59
sf::Ftp::TransferMode::Ebcdic
@ Ebcdic
Text mode using EBCDIC encoding.
Definition Ftp.hpp:60
sf::Ftp::deleteFile
Response deleteFile(const std::filesystem::path &name)
Remove an existing file.
sf::Ftp::createDirectory
Response createDirectory(const std::string &name)
Create a new directory.
sf::Ftp::deleteDirectory
Response deleteDirectory(const std::string &name)
Remove an existing directory.
sf::Ftp::~Ftp
~Ftp()
Destructor.
sf::Ftp::sendCommand
Response sendCommand(const std::string &command, const std::string &parameter="")
Send a command to the FTP server.
sf::Ftp::connect
Response connect(IpAddress server, unsigned short port=21, Time timeout=Time::Zero)
Connect to the specified FTP server.
sf::Ftp::login
Response login()
Log in using an anonymous account.
sf::Ftp::getWorkingDirectory
DirectoryResponse getWorkingDirectory()
Get the current working directory.
sf::Ftp::changeDirectory
Response changeDirectory(const std::string &directory)
Change the current working directory.
sf::Ftp::DataChannel
friend class DataChannel
Definition Ftp.hpp:547
sf::Ftp::getDirectoryListing
ListingResponse getDirectoryListing(const std::string &directory="")
Get the contents of the given directory.
sf::Ftp::download
Response download(const std::filesystem::path &remoteFile, const std::filesystem::path &localPath, TransferMode mode=TransferMode::Binary)
Download a file from the server.
sf::Ftp::renameFile
Response renameFile(const std::filesystem::path &file, const std::filesystem::path &newName)
Rename an existing file.
sf::Ftp::login
Response login(const std::string &name, const std::string &password)
Log in using a username and a password.
sf::Ftp::keepAlive
Response keepAlive()
Send a null command to keep the connection alive.
sf::Ftp::Ftp
Ftp(const Ftp &)=delete
Deleted copy constructor.
sf::Ftp::Ftp
Ftp()=default
Default constructor.
sf::Ftp::disconnect
Response disconnect()
Close the connection with the server.
sf::Ftp::parentDirectory
Response parentDirectory()
Go to the parent directory of the current one.
sf::Ftp::upload
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.
sf::Ftp::operator=
Ftp & operator=(const Ftp &)=delete
Deleted copy assignment.
sf::IpAddress
Encapsulate an IPv4 network address.
Definition IpAddress.hpp:49
sf::TcpSocket
Specialized socket using the TCP protocol.
Definition TcpSocket.hpp:54
sf::Time
Represents a time value.
Definition Time.hpp:42
sf::Time::Zero
static const Time Zero
Predefined "zero" time value.
Definition Time.hpp:110
sf
Definition AudioResource.hpp:36