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-2023 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#ifndef SFML_FTP_HPP
26#define SFML_FTP_HPP
27
29// Headers
34#include <SFML/System/Time.hpp>
35#include <string>
36#include <vector>
37
38
39namespace sf
40{
41class IpAddress;
42
48{
49public:
50
61
67 {
68 public:
69
74 enum Status
75 {
76 // 1xx: the requested action is being initiated,
77 // expect another reply before proceeding with a new command
82
83 // 2xx: the requested action has been successfully completed
84 Ok = 200,
88 FileStatus = 213,
90 SystemType = 215,
96 LoggedIn = 230,
99
100 // 3xx: the command has been accepted, but the requested action
101 // is dormant, pending receipt of further information
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
114
115 // 5xx: the command was not accepted and
116 // the requested action did not take place
128
129 // 10xx: SFML custom codes
134 };
135
146 explicit Response(Status code = InvalidResponse, const std::string& message = "");
147
157 bool isOk() const;
158
166
173 const std::string& getMessage() const;
174
175 private:
176
178 // Member data
180 Status m_status;
181 std::string m_message;
182 };
183
189 {
190 public:
191
198 DirectoryResponse(const Response& response);
199
206 const std::string& getDirectory() const;
207
208 private:
209
211 // Member data
213 std::string m_directory;
214 };
215
216
222 {
223 public:
224
232 ListingResponse(const Response& response, const std::string& data);
233
240 const std::vector<std::string>& getListing() const;
241
242 private:
243
245 // Member data
247 std::vector<std::string> m_listing;
248 };
249
250
259
281 Response connect(const IpAddress& server, unsigned short port = 21, Time timeout = Time::Zero);
282
292
303
316 Response login(const std::string& name, const std::string& password);
317
328
341
357 ListingResponse getDirectoryListing(const std::string& directory = "");
358
371 Response changeDirectory(const std::string& directory);
372
382
396 Response createDirectory(const std::string& name);
397
413 Response deleteDirectory(const std::string& name);
414
429 Response renameFile(const std::string& file, const std::string& newName);
430
446 Response deleteFile(const std::string& name);
447
468 Response download(const std::string& remoteFile, const std::string& localPath, TransferMode mode = Binary);
469
491 Response upload(const std::string& localFile, const std::string& remotePath, TransferMode mode = Binary, bool append = false);
492
509 Response sendCommand(const std::string& command, const std::string& parameter = "");
510
511private:
512
522 Response getResponse();
523
529 class DataChannel;
530
531 friend class DataChannel;
532
534 // Member data
536 TcpSocket m_commandSocket;
537 std::string m_receiveBuffer;
538};
539
540} // namespace sf
541
542
543#endif // SFML_FTP_HPP
544
545
#define SFML_NETWORK_API
Specialization of FTP response returning a directory.
Definition Ftp.hpp:189
DirectoryResponse(const Response &response)
Default constructor.
const std::string & getDirectory() const
Get the directory returned in the response.
Specialization of FTP response returning a filename listing.
Definition Ftp.hpp:222
const std::vector< std::string > & getListing() const
Return the array of directory/file names.
ListingResponse(const Response &response, const std::string &data)
Default constructor.
Define a FTP response.
Definition Ftp.hpp:67
bool isOk() const
Check if the status code means a success.
Status getStatus() const
Get the status code of the response.
const std::string & getMessage() const
Get the full message contained in the response.
Response(Status code=InvalidResponse, const std::string &message="")
Default constructor.
Status
Status codes possibly returned by a FTP response.
Definition Ftp.hpp:75
@ NeedInformation
Requested file action pending further information.
Definition Ftp.hpp:104
@ FilenameNotAllowed
Requested action not taken, file name not allowed.
Definition Ftp.hpp:127
@ DirectoryOk
PATHNAME created.
Definition Ftp.hpp:98
@ RestartMarkerReply
Restart marker reply.
Definition Ftp.hpp:78
@ NeedAccountToStore
Need account for storing files.
Definition Ftp.hpp:123
@ ServiceReadySoon
Service ready in N minutes.
Definition Ftp.hpp:79
@ CommandNotImplemented
Command not implemented.
Definition Ftp.hpp:119
@ PointlessCommand
Command not implemented.
Definition Ftp.hpp:85
@ FileUnavailable
Requested action not taken, file unavailable.
Definition Ftp.hpp:124
@ ServiceUnavailable
Service not available, closing control connection.
Definition Ftp.hpp:108
@ EnteringPassiveMode
Entering passive mode.
Definition Ftp.hpp:95
@ ConnectionFailed
Not part of the FTP standard, generated by SFML when the low-level socket connection with the server ...
Definition Ftp.hpp:131
@ LoggedIn
User logged in, proceed. Logged out if appropriate.
Definition Ftp.hpp:96
@ InvalidResponse
Not part of the FTP standard, generated by SFML when a received response cannot be parsed.
Definition Ftp.hpp:130
@ InsufficientStorageSpace
Requested action not taken; insufficient storage space in system, file unavailable.
Definition Ftp.hpp:113
@ DataConnectionUnavailable
Can't open data connection.
Definition Ftp.hpp:109
@ CommandUnknown
Syntax error, command unrecognized.
Definition Ftp.hpp:117
@ SystemType
NAME system type, where NAME is an official system name from the list in the Assigned Numbers documen...
Definition Ftp.hpp:90
@ OpeningDataConnection
File status ok, about to open data connection.
Definition Ftp.hpp:81
@ TransferAborted
Connection closed, transfer aborted.
Definition Ftp.hpp:110
@ HelpMessage
Help message.
Definition Ftp.hpp:89
@ DirectoryStatus
Directory status.
Definition Ftp.hpp:87
@ ParameterNotImplemented
Command not implemented for that parameter.
Definition Ftp.hpp:121
@ NeedPassword
User name ok, need password.
Definition Ftp.hpp:102
@ SystemStatus
System status, or system help reply.
Definition Ftp.hpp:86
@ NeedAccountToLogIn
Need account for login.
Definition Ftp.hpp:103
@ Ok
Command ok.
Definition Ftp.hpp:84
@ ClosingConnection
Service closing control connection.
Definition Ftp.hpp:92
@ ClosingDataConnection
Closing data connection, requested file action successful.
Definition Ftp.hpp:94
@ BadCommandSequence
Bad sequence of commands.
Definition Ftp.hpp:120
@ ConnectionClosed
Not part of the FTP standard, generated by SFML when the low-level socket connection is unexpectedly ...
Definition Ftp.hpp:132
@ PageTypeUnknown
Requested action aborted, page type unknown.
Definition Ftp.hpp:125
@ DataConnectionOpened
Data connection open, no transfer in progress.
Definition Ftp.hpp:93
@ LocalError
Requested action aborted, local error in processing.
Definition Ftp.hpp:112
@ ServiceReady
Service ready for new user.
Definition Ftp.hpp:91
@ FileStatus
File status.
Definition Ftp.hpp:88
@ InvalidFile
Not part of the FTP standard, generated by SFML when a local file cannot be read or written.
Definition Ftp.hpp:133
@ NotEnoughMemory
Requested file action aborted, exceeded storage allocation.
Definition Ftp.hpp:126
@ ParametersUnknown
Syntax error in parameters or arguments.
Definition Ftp.hpp:118
@ FileActionAborted
Requested file action not taken.
Definition Ftp.hpp:111
@ FileActionOk
Requested file action ok.
Definition Ftp.hpp:97
@ DataConnectionAlreadyOpened
Data connection already opened, transfer starting.
Definition Ftp.hpp:80
@ NotLoggedIn
Not logged in.
Definition Ftp.hpp:122
A FTP client.
Definition Ftp.hpp:48
Response upload(const std::string &localFile, const std::string &remotePath, TransferMode mode=Binary, bool append=false)
Upload a file to the server.
TransferMode
Enumeration of transfer modes.
Definition Ftp.hpp:56
@ Binary
Binary mode (file is transfered as a sequence of bytes)
Definition Ftp.hpp:57
@ Ebcdic
Text mode using EBCDIC encoding.
Definition Ftp.hpp:59
@ Ascii
Text mode using ASCII encoding.
Definition Ftp.hpp:58
Response download(const std::string &remoteFile, const std::string &localPath, TransferMode mode=Binary)
Download a file from the server.
Response createDirectory(const std::string &name)
Create a new directory.
Response deleteDirectory(const std::string &name)
Remove an existing directory.
~Ftp()
Destructor.
Response sendCommand(const std::string &command, const std::string &parameter="")
Send a command to the FTP server.
Response login()
Log in using an anonymous account.
DirectoryResponse getWorkingDirectory()
Get the current working directory.
Response changeDirectory(const std::string &directory)
Change the current working directory.
Response deleteFile(const std::string &name)
Remove an existing file.
friend class DataChannel
Definition Ftp.hpp:531
ListingResponse getDirectoryListing(const std::string &directory="")
Get the contents of the given directory.
Response renameFile(const std::string &file, const std::string &newName)
Rename an existing file.
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.
Response disconnect()
Close the connection with the server.
Response parentDirectory()
Go to the parent directory of the current one.
Response connect(const IpAddress &server, unsigned short port=21, Time timeout=Time::Zero)
Connect to the specified FTP server.
Encapsulate an IPv4 network address.
Definition IpAddress.hpp:45
NonCopyable()
Default constructor.
Specialized socket using the TCP protocol.
Definition TcpSocket.hpp:47
Represents a time value.
Definition Time.hpp:41
static const Time Zero
Predefined "zero" time value.
Definition Time.hpp:85