1 #include <string> 2 #include <File.h> 3 #include <stdio.h> 4 #include <NetworkKit.h> 5 6 using std::string; 7 8 class FtpClient 9 { 10 public: 11 FtpClient(); 12 ~FtpClient(); 13 14 enum ftp_mode 15 { 16 binary_mode, 17 ascii_mode 18 }; 19 20 bool connect(const string &server, const string &login, const string &passwd); 21 bool putFile(const string &local, const string &remote, ftp_mode mode = binary_mode); 22 bool getFile(const string &remote, const string &local, ftp_mode mode = binary_mode); 23 bool moveFile(const string &oldpath, const string &newpath); 24 bool cd(const string &dir); 25 bool pwd(string &dir); 26 bool ls(string &listing); 27 28 void setPassive(bool on); 29 30 protected: 31 enum { 32 ftp_complete = 1UL, 33 ftp_connected = 2, 34 ftp_passive = 4 35 }; 36 37 unsigned long m_state; 38 bool p_testState(unsigned long state); 39 void p_setState(unsigned long state); 40 void p_clearState(unsigned long state); 41 42 bool p_sendRequest(const string &cmd); 43 bool p_getReply(string &outstr, int &outcode, int &codetype); 44 bool p_getReplyLine(string &line); 45 bool p_openDataConnection(); 46 bool p_acceptDataConnection(); 47 48 BNetEndpoint *m_control; 49 BNetEndpoint *m_data; 50 51 }; 52 53 /* 54 * Definitions for the TELNET protocol. Snarfed from the BSD source. 55 */ 56 #define IAC 255 57 #define DONT 254 58 #define DO 253 59 #define WONT 252 60 #define WILL 251 61 #define xEOF 236 62 63