1
2
3
4
5
6 #ifndef _FtpClient_h
7 #define _FtpClient_h
8
9 using namespace std;
10
11 #include <Application.h>
12 #include <NetEndpoint.h>
13 #include <string>
14
15 #define CONNECT_COMPLETE 'conc'
16 #define PUT_COMPLETE 'putc'
17 #define GET_COMPLETE 'getc'
18 #define MOVE_COMPLETE 'movc'
19 #define MAKE_COMPLETE 'makc'
20 #define CD_COMPLETE 'cdco'
21 #define PWD_COMPLETE 'pwdc'
22 #define LS_COMPLETE 'lscm'
23 #define AMOUNT_SENT 'amst'
24
25 class FtpClient
26 {
27 public:
28 FtpClient(BHandler *handler = NULL);
29 ~FtpClient();
30
31 enum ftp_mode
32 {
33 binary_mode,
34 ascii_mode
35 };
36
37 bool connect(const string &server, const string &login, const string &passwd);
38 bool putFile(const string &local, const string &remote, ftp_mode mode = binary_mode);
39 bool getFile(const string &remote, const string &local, ftp_mode mode = binary_mode);
40 bool moveFile(const string &oldpath, const string &newpath);
41 bool makeDir(const string &newdir);
42 bool cd(const string &dir);
43 bool pwd(string &dir);
44 bool ls(BString &listing);
45 void setPassive(bool on);
46
47 public:
48 enum {
49 ftp_complete = 1UL,
50 ftp_connected = 2,
51 ftp_passive = 4
52 };
53
54 unsigned long m_state;
55 bool p_testState(unsigned long state);
56 void p_setState(unsigned long state);
57 void p_clearState(unsigned long state);
58
59 bool p_sendRequest(const string &cmd);
60 bool p_getReply(string &outstr, int &outcode, int &codetype);
61 bool p_getReplyLine(string &line);
62 bool p_openDataConnection();
63 bool p_acceptDataConnection();
64
65 BNetEndpoint *m_control;
66 BNetEndpoint *m_data;
67 BHandler *mHandler;
68 BLooper *mLooper;
69
70 };
71