]> git.saurik.com Git - wxWidgets.git/blob - include/wx/protocol/ftp.h
b9194c7db180e9defc1f40a187d58ddbd9069c91
[wxWidgets.git] / include / wx / protocol / ftp.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: ftp.h
3 // Purpose: FTP protocol
4 // Author: Vadim Zeitlin
5 // Modified by: Mark Johnson, wxWindows@mj10777.de
6 // 20000917 : RmDir, GetLastResult, GetList
7 // Created: 07/07/1997
8 // RCS-ID: $Id$
9 // Copyright: (c) 1997, 1998 Guilhem Lavaux
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef __WX_FTP_H__
14 #define __WX_FTP_H__
15
16 #ifdef __GNUG__
17 #pragma interface
18 #endif
19
20 #include "wx/object.h"
21 #include "wx/sckaddr.h"
22 #include "wx/protocol/protocol.h"
23 #include "wx/url.h"
24
25 class WXDLLEXPORT wxFTP : public wxProtocol
26 {
27 public:
28 enum TransferMode
29 {
30 ASCII,
31 BINARY
32 };
33
34 wxFTP();
35 virtual ~wxFTP();
36
37 // Connecting and disconnecting
38 void SetUser(const wxString& user) { m_user = user; }
39 void SetPassword(const wxString& passwd) { m_passwd = passwd; }
40
41 bool Connect(wxSockAddress& addr, bool wait = TRUE);
42 bool Connect(const wxString& host);
43
44 // disconnect
45 virtual bool Close();
46
47 // Parameters set up
48
49 // set transfer mode now
50 bool SetBinary() { return SetTransferMode(BINARY); }
51 bool SetAscii() { return SetTransferMode(ASCII); }
52 bool SetTransferMode(TransferMode mode);
53
54 // Generic FTP interface
55
56 // the error code
57 virtual wxProtocolError GetError() { return m_lastError; }
58
59 // the last FTP server reply
60 const wxString& GetLastResult() { return m_lastResult; }
61
62 // send any FTP command (should be full FTP command line but without
63 // trailing "\r\n") and return its return code
64 char SendCommand(const wxString& command);
65
66 // check that the command returned the given code
67 bool CheckCommand(const wxString& command, char expectedReturn)
68 {
69 return SendCommand(command) == expectedReturn;
70 }
71
72 // Filesystem commands
73 bool ChDir(const wxString& dir);
74 bool MkDir(const wxString& dir);
75 bool RmDir(const wxString& dir);
76 wxString Pwd();
77 bool Rename(const wxString& src, const wxString& dst);
78 bool RmFile(const wxString& path);
79
80 // Download methods
81 bool Abort();
82
83 virtual wxInputStream *GetInputStream(const wxString& path);
84 virtual wxOutputStream *GetOutputStream(const wxString& path);
85
86 // Directory listing
87
88 // get the list of full filenames, the format is fixed: one file name per
89 // line
90 bool GetFilesList(wxArrayString& files,
91 const wxString& wildcard = wxEmptyString)
92 {
93 return GetList(files, wildcard, FALSE);
94 }
95
96 // get a directory list in server dependent format - this can be shown
97 // directly to the user
98 bool GetDirList(wxArrayString& files,
99 const wxString& wildcard = wxEmptyString)
100 {
101 return GetList(files, wildcard, TRUE);
102 }
103
104 // equivalent to either GetFilesList() (default) or GetDirList()
105 bool GetList(wxArrayString& files,
106 const wxString& wildcard = wxEmptyString,
107 bool details = FALSE);
108
109 #ifdef WXWIN_COMPATIBILITY_2
110 // deprecated
111 wxList *GetList(const wxString& wildcard, bool details = FALSE);
112 #endif // WXWIN_COMPATIBILITY_2
113
114 protected:
115 // this executes a simple ftp command with the given argument and returns
116 // TRUE if it its return code starts with '2'
117 bool DoSimpleCommand(const wxChar *command,
118 const wxString& arg = wxEmptyString);
119
120 // get the server reply, return the first character of the reply code,
121 // '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occured
122 char GetResult();
123
124 // check that the result is equal to expected value
125 bool CheckResult(char ch) { return GetResult() == ch; }
126
127 wxSocketClient *GetPort();
128
129 wxString m_user,
130 m_passwd;
131
132 wxString m_lastResult;
133 wxProtocolError m_lastError;
134
135 // true if there is an FTP transfer going on
136 bool m_streaming;
137
138 // true if the user had set the transfer mode
139 bool m_modeSet;
140
141 friend class wxInputFTPStream;
142 friend class wxOutputFTPStream;
143
144 DECLARE_DYNAMIC_CLASS(wxFTP)
145 DECLARE_PROTOCOL(wxFTP)
146 };
147
148 #endif // __WX_FTP_H__