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/Utilities/NonCopyable.hpp>
00032 #include <SFML/Network/IPAddress.hpp>
00033 #include <SFML/Network/SocketTCP.hpp>
00034 #include <vector>
00035
00036
00041 class sfFTP : sfNonCopyable
00042 {
00043 public :
00044
00049 class Listener
00050 {
00051 public :
00052
00057 virtual ~Listener() {}
00058
00059 private :
00060
00061 friend sfFTP;
00062
00070 virtual void OnResponse(unsigned int Code, const std::string& Message) = 0;
00071 };
00072
00076 enum TransferMode
00077 {
00078 Binary,
00079 Ascii,
00080 Ebcdic
00081 };
00082
00089 sfFTP(Listener* FTPListener = NULL);
00090
00095 ~sfFTP();
00096
00106 bool Connect(const sfIPAddress& Server, unsigned int Port = 21);
00107
00115 bool Login(const std::string& UserName, const std::string& Password);
00116
00123 bool Disconnect();
00124
00131 bool KeepAlive();
00132
00141 bool GetWorkingDirectory(std::string& Directory);
00142
00153 bool GetDirectoryListing(std::vector<std::string>& Listing, const std::string& Directory = "");
00154
00163 bool ChangeDirectory(const std::string& Directory);
00164
00171 bool ParentDirectory();
00172
00181 bool MakeDirectory(const std::string& Name);
00182
00191 bool DeleteDirectory(const std::string& Name);
00192
00202 bool RenameFile(const std::string& File, const std::string& NewName);
00203
00212 bool RemoveFile(const std::string& Name);
00213
00224 bool Download(const std::string& DistantFile, const std::string& DestPath, TransferMode Mode = Binary);
00225
00236 bool Upload(const std::string& LocalFile, const std::string& DestPath, TransferMode Mode = Binary);
00237
00238 private :
00239
00249 bool SendCommand(const std::string& Command, const std::string& Parameter = "");
00250
00258 bool GetResponse();
00259
00264 class DataChannel
00265 {
00266 public :
00267
00274 DataChannel(sfFTP& FTP);
00275
00280 ~DataChannel();
00281
00291 bool Open(TransferMode Mode, unsigned short Port = 20);
00292
00299 void Send(const std::vector<char>& Data);
00300
00307 void Receive(std::vector<char>& Data);
00308
00309 private :
00310
00312
00314 sfFTP& myFTP;
00315 sfSocketTCP myDataSocket;
00316 };
00317
00318 friend DataChannel;
00319
00321
00323 sfSocketTCP myCommandSocket;
00324 std::string myLastMessage;
00325 Listener* myListener;
00326 };
00327
00328
00329 #endif // SFML_FTP_HPP