xref: /haiku/src/apps/codycam/FtpClient.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
1 #ifndef FTP_CLIENT_H
2 #define FTP_CLIENT_H
3 
4 
5 #include <stdio.h>
6 #include <string>
7 
8 #include <File.h>
9 #include <NetworkKit.h>
10 #include "FileUploadClient.h"
11 
12 using std::string;
13 
14 
15 /*
16  * Definitions for the TELNET protocol. Snarfed from the BSD source.
17  */
18 #define IAC     255
19 #define DONT    254
20 #define DO      253
21 #define WONT    252
22 #define WILL    251
23 #define xEOF    236
24 
25 
26 class FtpClient : public FileUploadClient {
27 	public:
28 		FtpClient();
29 		~FtpClient();
30 
31 		bool Connect(const string& server, const string& login,
32 			const string& passwd);
33 
34 		bool PutFile(const string& local, const string& remote,
35 			ftp_mode mode = binary_mode);
36 
37 		bool GetFile(const string& remote, const string& local,
38 			ftp_mode mode = binary_mode);
39 
40 		bool MoveFile(const string& oldPath, const string& newPath);
41 		bool ChangeDir(const string& dir);
42 		bool PrintWorkingDir(string& dir);
43 		bool ListDirContents(string& listing);
44 		bool Chmod(const string& path, const string& mod);
45 
46 		void SetPassive(bool on);
47 
48 	protected:
49 		enum {
50 			ftp_complete = 1UL,
51 			ftp_connected = 2,
52 			ftp_passive = 4
53 		};
54 
55 		bool _TestState(unsigned long state);
56 		void _SetState(unsigned long state);
57 		void _ClearState(unsigned long state);
58 
59 		bool _SendRequest(const string& cmd);
60 		bool _GetReply(string& outString, int& outCode, int& codeType);
61 		bool _GetReplyLine(string& line);
62 		bool _OpenDataConnection();
63 		bool _AcceptDataConnection();
64 
65 		unsigned long fState;
66 		BNetEndpoint* fControl;
67 		BNetEndpoint* fData;
68 
69 };
70 
71 #endif	// FTP_CLIENT_H
72