Documentation of SFML 2.0

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
Ftp.hpp
1 
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
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
31 #include <SFML/Network/Export.hpp>
32 #include <SFML/Network/TcpSocket.hpp>
33 #include <SFML/System/NonCopyable.hpp>
34 #include <SFML/System/Time.hpp>
35 #include <string>
36 #include <vector>
37 
38 
39 namespace sf
40 {
41 class IpAddress;
42 
47 class SFML_NETWORK_API Ftp : NonCopyable
48 {
49 public :
50 
56  {
59  Ebcdic
60  };
61 
66  class SFML_NETWORK_API Response
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
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 = InvalidResponse, const std::string& message = "");
147 
157  bool isOk() const;
158 
165  Status getStatus() const;
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 
188  class SFML_NETWORK_API DirectoryResponse : public Response
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 
221  class SFML_NETWORK_API ListingResponse : public Response
222  {
223  public :
224 
232  ListingResponse(const Response& response, const std::vector<char>& 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 
258  ~Ftp();
259 
281  Response connect(const IpAddress& server, unsigned short port = 21, Time timeout = Time::Zero);
282 
291  Response disconnect();
292 
302  Response login();
303 
316  Response login(const std::string& name, const std::string& password);
317 
327  Response keepAlive();
328 
340  DirectoryResponse getWorkingDirectory();
341 
357  ListingResponse getDirectoryListing(const std::string& directory = "");
358 
371  Response changeDirectory(const std::string& directory);
372 
381  Response parentDirectory();
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 
465  Response download(const std::string& remoteFile, const std::string& localPath, TransferMode mode = Binary);
466 
484  Response upload(const std::string& localFile, const std::string& remotePath, TransferMode mode = Binary);
485 
486 private :
487 
497  Response sendCommand(const std::string& command, const std::string& parameter = "");
498 
508  Response getResponse();
509 
515  class DataChannel;
516 
517  friend class DataChannel;
518 
520  // Member data
522  TcpSocket m_commandSocket;
523 };
524 
525 } // namespace sf
526 
527 
528 #endif // SFML_FTP_HPP
529 
530