]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/protocol/ftp.h
few other fixes for wxChar => wxString
[wxWidgets.git] / interface / wx / protocol / ftp.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: protocol/ftp.h
e54c96f1 3// Purpose: interface of wxFTP
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
a30b5ab9
FM
9/**
10 Transfer modes used by wxFTP.
11*/
12enum TransferMode
13{
14 NONE, //!< not set by user explicitly.
15 ASCII,
16 BINARY
17};
18
23324ae1
FM
19/**
20 @class wxFTP
7c913512 21
23324ae1
FM
22 wxFTP can be used to establish a connection to an FTP server and perform all the
23 usual operations. Please consult the RFC 959 for more details about the FTP
24 protocol.
7c913512 25
a30b5ab9 26 To use a command which doesn't involve file transfer (i.e. directory oriented
23324ae1 27 commands) you just need to call a corresponding member function or use the
a30b5ab9
FM
28 generic wxFTP::SendCommand() method.
29 However to actually transfer files you just get or give a stream to or from this
30 class and the actual data are read or written using the usual stream methods.
7c913512 31
23324ae1 32 Example of using wxFTP for file downloading:
7c913512 33
23324ae1 34 @code
a30b5ab9 35 wxFTP ftp;
7c913512 36
23324ae1
FM
37 // if you don't use these lines anonymous login will be used
38 ftp.SetUser("user");
39 ftp.SetPassword("password");
7c913512 40
23324ae1
FM
41 if ( !ftp.Connect("ftp.wxwindows.org") )
42 {
43 wxLogError("Couldn't connect");
44 return;
45 }
7c913512 46
23324ae1
FM
47 ftp.ChDir("/pub");
48 wxInputStream *in = ftp.GetInputStream("wxWidgets-4.2.0.tar.gz");
49 if ( !in )
50 {
51 wxLogError("Coudln't get file");
52 }
53 else
54 {
55 size_t size = in-GetSize();
56 char *data = new char[size];
a30b5ab9 57 if ( !in->Read(data, size) )
23324ae1
FM
58 {
59 wxLogError("Read error");
60 }
61 else
62 {
63 // file data is in the buffer
64 ...
65 }
7c913512 66
23324ae1
FM
67 delete [] data;
68 delete in;
69 }
70 @endcode
7c913512 71
23324ae1
FM
72 To upload a file you would do (assuming the connection to the server was opened
73 successfully):
7c913512 74
23324ae1 75 @code
a30b5ab9
FM
76 wxOutputStream *out = ftp.GetOutputStream("filename");
77 if ( out )
78 {
79 out->Write(...); // your data
80 delete out;
81 }
23324ae1 82 @endcode
7c913512 83
23324ae1
FM
84 @library{wxnet}
85 @category{net}
7c913512 86
e54c96f1 87 @see wxSocketBase
23324ae1
FM
88*/
89class wxFTP : public wxProtocol
90{
91public:
92 /**
93 Default constructor.
94 */
4cc4bfaf 95 wxFTP();
23324ae1
FM
96
97 /**
98 Destructor will close the connection if connected.
99 */
adaaa686 100 virtual ~wxFTP();
23324ae1
FM
101
102 /**
7c913512 103 Aborts the download currently in process, returns @true if ok, @false
23324ae1
FM
104 if an error occurred.
105 */
adaaa686 106 virtual bool Abort();
23324ae1
FM
107
108 /**
109 Change the current FTP working directory.
110 Returns @true if successful.
111 */
112 bool ChDir(const wxString& dir);
113
114 /**
4cc4bfaf 115 Send the specified @a command to the FTP server. @a ret specifies
23324ae1 116 the expected result.
a30b5ab9 117
d29a9a8a 118 @return @true if the command has been sent successfully, else @false.
23324ae1
FM
119 */
120 bool CheckCommand(const wxString& command, char ret);
121
122 /**
123 Returns @true if the given remote file exists, @false otherwise.
124 */
125 bool FileExists(const wxString& filename);
126
127 /**
a30b5ab9 128 The GetList() function is quite low-level. It returns the list of the files in
4cc4bfaf 129 the current directory. The list can be filtered using the @a wildcard string.
a30b5ab9 130
4cc4bfaf 131 If @a wildcard is empty (default), it will return all files in directory.
23324ae1
FM
132 The form of the list can change from one peer system to another. For example,
133 for a UNIX peer system, it will look like this:
a30b5ab9
FM
134
135 @verbatim
136 -r--r--r-- 1 guilhem lavaux 12738 Jan 16 20:17 cmndata.cpp
137 -r--r--r-- 1 guilhem lavaux 10866 Jan 24 16:41 config.cpp
138 -rw-rw-rw- 1 guilhem lavaux 29967 Dec 21 19:17 cwlex_yy.c
139 -rw-rw-rw- 1 guilhem lavaux 14342 Jan 22 19:51 cwy_tab.c
140 -r--r--r-- 1 guilhem lavaux 13890 Jan 29 19:18 date.cpp
141 -r--r--r-- 1 guilhem lavaux 3989 Feb 8 19:18 datstrm.cpp
142 @endverbatim
143
23324ae1 144 But on Windows system, it will look like this:
a30b5ab9
FM
145
146 @verbatim
147 winamp~1 exe 520196 02-25-1999 19:28 winamp204.exe
148 1 file(s) 520 196 bytes
149 @endverbatim
150
151 @return @true if the file list was successfully retrieved, @false otherwise.
152
4cc4bfaf 153 @see GetFilesList()
23324ae1
FM
154 */
155 bool GetDirList(wxArrayString& files,
43c48e1e 156 const wxString& wildcard = wxEmptyString);
23324ae1
FM
157
158 /**
159 Returns the file size in bytes or -1 if the file doesn't exist or the size
a30b5ab9
FM
160 couldn't be determined.
161
162 Notice that this size can be approximative size only and shouldn't be used
163 for allocating the buffer in which the remote file is copied, for example.
23324ae1
FM
164 */
165 int GetFileSize(const wxString& filename);
166
167 /**
168 This function returns the computer-parsable list of the files in the current
169 directory (optionally only of the files matching the @e wildcard, all files
a30b5ab9
FM
170 by default).
171
172 This list always has the same format and contains one full (including the
173 directory path) file name per line.
174
d29a9a8a 175 @return @true if the file list was successfully retrieved, @false otherwise.
a30b5ab9
FM
176
177 @see GetDirList()
23324ae1
FM
178 */
179 bool GetFilesList(wxArrayString& files,
43c48e1e 180 const wxString& wildcard = wxEmptyString);
23324ae1
FM
181
182 /**
a30b5ab9
FM
183 Creates a new input stream on the specified path.
184
185 You can use all but the seek functionality of wxStreamBase.
186 wxStreamBase::Seek() isn't available on all streams. For example, HTTP or FTP
187 streams do not deal with it. Other functions like wxStreamBase::Tell() are
188 not available for this sort of stream, at present.
189
23324ae1 190 You will be notified when the EOF is reached by an error.
a30b5ab9 191
d29a9a8a 192 @return Returns @NULL if an error occurred (it could be a network failure
4cc4bfaf 193 or the fact that the file doesn't exist).
23324ae1 194 */
adaaa686 195 virtual wxInputStream* GetInputStream(const wxString& path);
23324ae1
FM
196
197 /**
a30b5ab9 198 Returns the last command result, i.e. the full server reply for the last command.
23324ae1 199 */
43c48e1e 200 const wxString& GetLastResult();
23324ae1
FM
201
202 /**
a30b5ab9
FM
203 Initializes an output stream to the specified @e file.
204
205 The returned stream has all but the seek functionality of wxStreams.
206 When the user finishes writing data, he has to delete the stream to close it.
207
d29a9a8a 208 @return An initialized write-only stream.
a30b5ab9 209
4cc4bfaf 210 @see wxOutputStream
23324ae1 211 */
adaaa686 212 virtual wxOutputStream* GetOutputStream(const wxString& file);
23324ae1
FM
213
214 /**
215 Create the specified directory in the current FTP working directory.
216 Returns @true if successful.
217 */
218 bool MkDir(const wxString& dir);
219
220 /**
221 Returns the current FTP working directory.
222 */
4cc4bfaf 223 wxString Pwd();
23324ae1
FM
224
225 /**
4cc4bfaf 226 Rename the specified @a src element to @e dst. Returns @true if successful.
23324ae1
FM
227 */
228 bool Rename(const wxString& src, const wxString& dst);
229
230 /**
231 Remove the specified directory from the current FTP working directory.
232 Returns @true if successful.
233 */
234 bool RmDir(const wxString& dir);
235
236 /**
237 Delete the file specified by @e path. Returns @true if successful.
238 */
239 bool RmFile(const wxString& path);
240
241 /**
4cc4bfaf 242 Send the specified @a command to the FTP server and return the first
23324ae1
FM
243 character of the return code.
244 */
245 char SendCommand(const wxString& command);
246
247 /**
248 Sets the transfer mode to ASCII. It will be used for the next transfer.
249 */
250 bool SetAscii();
251
252 /**
253 Sets the transfer mode to binary (IMAGE). It will be used for the next transfer.
254 */
255 bool SetBinary();
256
257 /**
a30b5ab9
FM
258 If @a pasv is @true, passive connection to the FTP server is used.
259
260 This is the default as it works with practically all firewalls.
261 If the server doesn't support passive move, you may call this function with
262 @false argument to use active connection.
23324ae1
FM
263 */
264 void SetPassive(bool pasv);
265
266 /**
267 Sets the password to be sent to the FTP server to be allowed to log in.
268 */
adaaa686 269 virtual void SetPassword(const wxString& passwd);
23324ae1
FM
270
271 /**
272 Sets the transfer mode to the specified one. It will be used for the next
273 transfer.
a30b5ab9 274
23324ae1
FM
275 If this function is never called, binary transfer mode is used by default.
276 */
277 bool SetTransferMode(TransferMode mode);
278
279 /**
280 Sets the user name to be sent to the FTP server to be allowed to log in.
281 */
adaaa686 282 virtual void SetUser(const wxString& user);
23324ae1 283};
e54c96f1 284