Documentation of SFML 1.6

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-2009 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/System/NonCopyable.hpp>
32 #include <SFML/Network/SocketTCP.hpp>
33 #include <string>
34 #include <vector>
35 
36 
37 namespace sf
38 {
39 class IPAddress;
40 
47 class SFML_API Ftp : NonCopyable
48 {
49 public :
50 
55  {
58  Ebcdic
59  };
60 
66  class SFML_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 
143  Response(Status Code = InvalidResponse, const std::string& Message = "");
144 
152  bool IsOk() const;
153 
160  Status GetStatus() const;
161 
168  const std::string& GetMessage() const;
169 
170  private :
171 
173  // Member data
175  Status myStatus;
176  std::string myMessage;
177  };
178 
182  class SFML_API DirectoryResponse : public Response
183  {
184  public :
185 
193 
200  const std::string& GetDirectory() const;
201 
202  private :
203 
205  // Member data
207  std::string myDirectory;
208  };
209 
210 
214  class SFML_API ListingResponse : public Response
215  {
216  public :
217 
225  ListingResponse(Response Resp, const std::vector<char>& Data);
226 
233  std::size_t GetCount() const;
234 
243  const std::string& GetFilename(std::size_t Index) const;
244 
245  private :
246 
248  // Member data
250  std::vector<std::string> myFilenames;
251  };
252 
253 
258  ~Ftp();
259 
270  Response Connect(const IPAddress& Server, unsigned short Port = 21, float Timeout = 0.f);
271 
278  Response Login();
279 
289  Response Login(const std::string& UserName, const std::string& Password);
290 
297  Response Disconnect();
298 
305  Response KeepAlive();
306 
313  DirectoryResponse GetWorkingDirectory();
314 
324  ListingResponse GetDirectoryListing(const std::string& Directory = "");
325 
334  Response ChangeDirectory(const std::string& Directory);
335 
342  Response ParentDirectory();
343 
352  Response MakeDirectory(const std::string& Name);
353 
362  Response DeleteDirectory(const std::string& Name);
363 
373  Response RenameFile(const std::string& File, const std::string& NewName);
374 
383  Response DeleteFile(const std::string& Name);
384 
395  Response Download(const std::string& DistantFile, const std::string& DestPath, TransferMode Mode = Binary);
396 
407  Response Upload(const std::string& LocalFile, const std::string& DestPath, TransferMode Mode = Binary);
408 
409 private :
410 
420  Response SendCommand(const std::string& Command, const std::string& Parameter = "");
421 
429  Response GetResponse();
430 
435  class DataChannel;
436 
437  friend class DataChannel;
438 
440  // Member data
442  SocketTCP myCommandSocket;
443 };
444 
445 } // namespace sf
446 
447 
448 #endif // SFML_FTP_HPP