00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025 #ifndef SFML_FTP_HPP
00026 #define SFML_FTP_HPP
00027
00029
00031 #include <SFML/System/NonCopyable.hpp>
00032 #include <SFML/Network/TcpSocket.hpp>
00033 #include <string>
00034 #include <vector>
00035
00036
00037 namespace sf
00038 {
00039 class IpAddress;
00040
00045 class SFML_API Ftp : NonCopyable
00046 {
00047 public :
00048
00053 enum TransferMode
00054 {
00055 Binary,
00056 Ascii,
00057 Ebcdic
00058 };
00059
00064 class SFML_API Response
00065 {
00066 public :
00067
00072 enum Status
00073 {
00074
00075
00076 RestartMarkerReply = 110,
00077 ServiceReadySoon = 120,
00078 DataConnectionAlreadyOpened = 125,
00079 OpeningDataConnection = 150,
00080
00081
00082 Ok = 200,
00083 PointlessCommand = 202,
00084 SystemStatus = 211,
00085 DirectoryStatus = 212,
00086 FileStatus = 213,
00087 HelpMessage = 214,
00088 SystemType = 215,
00089 ServiceReady = 220,
00090 ClosingConnection = 221,
00091 DataConnectionOpened = 225,
00092 ClosingDataConnection = 226,
00093 EnteringPassiveMode = 227,
00094 LoggedIn = 230,
00095 FileActionOk = 250,
00096 DirectoryOk = 257,
00097
00098
00099
00100 NeedPassword = 331,
00101 NeedAccountToLogIn = 332,
00102 NeedInformation = 350,
00103
00104
00105
00106 ServiceUnavailable = 421,
00107 DataConnectionUnavailable = 425,
00108 TransferAborted = 426,
00109 FileActionAborted = 450,
00110 LocalError = 451,
00111 InsufficientStorageSpace = 452,
00112
00113
00114
00115 CommandUnknown = 500,
00116 ParametersUnknown = 501,
00117 CommandNotImplemented = 502,
00118 BadCommandSequence = 503,
00119 ParameterNotImplemented = 504,
00120 NotLoggedIn = 530,
00121 NeedAccountToStore = 532,
00122 FileUnavailable = 550,
00123 PageTypeUnknown = 551,
00124 NotEnoughMemory = 552,
00125 FilenameNotAllowed = 553,
00126
00127
00128 InvalidResponse = 1000,
00129 ConnectionFailed = 1001,
00130 ConnectionClosed = 1002,
00131 InvalidFile = 1003
00132 };
00133
00144 Response(Status code = InvalidResponse, const std::string& message = "");
00145
00155 bool IsOk() const;
00156
00163 Status GetStatus() const;
00164
00171 const std::string& GetMessage() const;
00172
00173 private :
00174
00176
00178 Status myStatus;
00179 std::string myMessage;
00180 };
00181
00186 class SFML_API DirectoryResponse : public Response
00187 {
00188 public :
00189
00196 DirectoryResponse(const Response& response);
00197
00204 const std::string& GetDirectory() const;
00205
00206 private :
00207
00209
00211 std::string myDirectory;
00212 };
00213
00214
00219 class SFML_API ListingResponse : public Response
00220 {
00221 public :
00222
00230 ListingResponse(const Response& response, const std::vector<char>& data);
00231
00238 const std::vector<std::string>& GetFilenames() const;
00239
00240 private :
00241
00243
00245 std::vector<std::string> myFilenames;
00246 };
00247
00248
00256 ~Ftp();
00257
00279 Response Connect(const IpAddress& server, unsigned short port = 21, Uint32 timeout = 0);
00280
00289 Response Disconnect();
00290
00300 Response Login();
00301
00314 Response Login(const std::string& name, const std::string& password);
00315
00325 Response KeepAlive();
00326
00338 DirectoryResponse GetWorkingDirectory();
00339
00355 ListingResponse GetDirectoryListing(const std::string& directory = "");
00356
00369 Response ChangeDirectory(const std::string& directory);
00370
00379 Response ParentDirectory();
00380
00394 Response CreateDirectory(const std::string& name);
00395
00411 Response DeleteDirectory(const std::string& name);
00412
00427 Response RenameFile(const std::string& file, const std::string& newName);
00428
00444 Response DeleteFile(const std::string& name);
00445
00463 Response Download(const std::string& remoteFile, const std::string& localPath, TransferMode mode = Binary);
00464
00480 Response Upload(const std::string& localFile, const std::string& remotePath, TransferMode mode = Binary);
00481
00482 private :
00483
00493 Response SendCommand(const std::string& command, const std::string& parameter = "");
00494
00504 Response GetResponse();
00505
00511 class DataChannel;
00512
00513 friend class DataChannel;
00514
00516
00518 TcpSocket myCommandSocket;
00519 };
00520
00521 }
00522
00523
00524 #endif // SFML_FTP_HPP
00525
00526