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