SFML logo
  • Main Page
  • Modules
  • Classes
  • Files
  • File List

Ftp.hpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00025 #ifndef SFML_FTP_HPP
00026 #define SFML_FTP_HPP
00027 
00029 // Headers
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             // 1xx: the requested action is being initiated,
00075             // expect another reply before proceeding with a new command
00076             RestartMarkerReply          = 110, 
00077             ServiceReadySoon            = 120, 
00078             DataConnectionAlreadyOpened = 125, 
00079             OpeningDataConnection       = 150, 
00080 
00081             // 2xx: the requested action has been successfully completed
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             // 3xx: the command has been accepted, but the requested action
00099             // is dormant, pending receipt of further information
00100             NeedPassword       = 331, 
00101             NeedAccountToLogIn = 332, 
00102             NeedInformation    = 350, 
00103 
00104             // 4xx: the command was not accepted and the requested action did not take place,
00105             // but the error condition is temporary and the action may be requested again
00106             ServiceUnavailable        = 421, 
00107             DataConnectionUnavailable = 425, 
00108             TransferAborted           = 426, 
00109             FileActionAborted         = 450, 
00110             LocalError                = 451, 
00111             InsufficientStorageSpace  = 452, 
00112 
00113             // 5xx: the command was not accepted and
00114             // the requested action did not take place
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             // 10xx: SFML custom codes
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         // Member data
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         // Member data
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         // Member data
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     // Member data
00518     TcpSocket myCommandSocket; 
00519 };
00520 
00521 } // namespace sf
00522 
00523 
00524 #endif // SFML_FTP_HPP
00525 
00526 

 ::  Copyright © 2007-2008 Laurent Gomila, all rights reserved  ::  Documentation generated by doxygen 1.5.2  ::