]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/ftp.tex
more LaTeX error fixes
[wxWidgets.git] / docs / latex / wx / ftp.tex
... / ...
CommitLineData
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%% Name: ftp.tex
3%% Purpose: wxFTP documentation
4%% Author: Guilhem Lavaux, Vadim Zeitlin
5%% Modified by:
6%% Created: ~1997
7%% RCS-ID: $Id$
8%% Copyright: (c) wxWidgets team
9%% License: wxWindows license
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12\section{\class{wxFTP}}\label{wxftp}
13
14wxFTP can be used to establish a connection to an FTP server and perform all the
15usual operations. Please consult the RFC 959 for more details about the FTP
16protocol.
17
18To use a commands which doesn't involve file transfer (i.e. directory oriented
19commands) you just need to call a corresponding member function or use the
20generic \helpref{SendCommand}{wxftpsendcommand} method. However to actually
21transfer files you just get or give a stream to or from this class and the
22actual data are read or written using the usual stream methods.
23
24Example of using wxFTP for file downloading:
25
26\begin{verbatim}
27 wxFTP ftp;
28
29 // if you don't use these lines anonymous login will be used
30 ftp.SetUser("user");
31 ftp.SetPassword("password");
32
33 if ( !ftp.Connect("ftp.wxwindows.org") )
34 {
35 wxLogError("Couldn't connect");
36 return;
37 }
38
39 ftp.ChDir("/pub");
40 wxInputStream *in = ftp.GetInputStream("wxWidgets-4.2.0.tar.gz");
41 if ( !in )
42 {
43 wxLogError("Coudln't get file");
44 }
45 else
46 {
47 size_t size = in->GetSize();
48 char *data = new char[size];
49 if ( !in->Read(data, size) )
50 {
51 wxLogError("Read error");
52 }
53 else
54 {
55 // file data is in the buffer
56 ...
57 }
58
59 delete [] data;
60 delete in;
61 }
62\end{verbatim}
63
64To upload a file you would do (assuming the connection to the server was opened
65successfully):
66
67\begin{verbatim}
68 wxOutputStream *out = ftp.GetOutputStream("filename");
69 if ( out )
70 {
71 out->Write(...); // your data
72 delete out;
73 }
74\end{verbatim}
75
76\wxheading{Constants}
77
78wxFTP defines constants corresponding to the two supported transfer modes:
79
80\begin{verbatim}
81enum TransferMode
82{
83 ASCII,
84 BINARY
85};
86\end{verbatim}
87
88\wxheading{Derived from}
89
90\helpref{wxProtocol}{wxprotocol}\\
91\helpref{wxSocketClient}{wxsocketclient}\\
92\helpref{wxSocketBase}{wxsocketbase}\\
93\helpref{wxObject}{wxobject}
94
95\wxheading{Include files}
96
97<wx/protocol/ftp.h>
98
99\wxheading{Library}
100
101\helpref{wxNet}{librarieslist}
102
103\wxheading{See also}
104
105\helpref{wxSocketBase}{wxsocketbase}
106
107% ----------------------------------------------------------------------------
108% Members
109% ----------------------------------------------------------------------------
110
111\latexignore{\rtfignore{\wxheading{Members}}}
112
113
114\membersection{wxFTP::wxFTP}\label{wxftpctor}
115
116\func{}{wxFTP}{\void}
117
118Default constructor.
119
120
121\membersection{wxFTP::\destruct{wxFTP}}\label{wxftpdtor}
122
123\func{}{\destruct{wxFTP}}{\void}
124
125Destructor will close the connection if connected.
126
127
128\membersection{wxFTP::Abort}\label{wxftpabort}
129
130\func{bool}{Abort}{\void}
131
132Aborts the download currently in process, returns \true if ok, \false
133if an error occurred.
134
135
136\membersection{wxFTP::CheckCommand}\label{wxftpcheckcommand}
137
138\func{bool}{CheckCommand}{\param{const wxString\&}{ command}, \param{char }{ret}}
139
140Send the specified {\it command} to the FTP server. {\it ret} specifies
141the expected result.
142
143\wxheading{Return value}
144
145true if the command has been sent successfully, else false.
146
147
148\membersection{wxFTP::SendCommand}\label{wxftpsendcommand}
149
150\func{char}{SendCommand}{\param{const wxString\&}{ command}}
151
152Send the specified {\it command} to the FTP server and return the first
153character of the return code.
154
155
156\membersection{wxFTP::GetLastResult}\label{wxftpgetlastresult}
157
158\func{const wxString\&}{GetLastResult}{\void}
159
160Returns the last command result, i.e. the full server reply for the last
161command.
162
163% ----------------------------------------------------------------------------
164
165
166\membersection{wxFTP::ChDir}\label{wxftpchdir}
167
168\func{bool}{ChDir}{\param{const wxString\&}{ dir}}
169
170Change the current FTP working directory.
171Returns true if successful.
172
173
174\membersection{wxFTP::MkDir}\label{wxftpmkdir}
175
176\func{bool}{MkDir}{\param{const wxString\&}{ dir}}
177
178Create the specified directory in the current FTP working directory.
179Returns true if successful.
180
181
182\membersection{wxFTP::RmDir}\label{wxftprmdir}
183
184\func{bool}{RmDir}{\param{const wxString\&}{ dir}}
185
186Remove the specified directory from the current FTP working directory.
187Returns true if successful.
188
189
190\membersection{wxFTP::Pwd}\label{wxftppwd}
191
192\func{wxString}{Pwd}{\void}
193
194Returns the current FTP working directory.
195
196% ----------------------------------------------------------------------------
197
198
199\membersection{wxFTP::Rename}\label{wxftprename}
200
201\func{bool}{Rename}{\param{const wxString\&}{ src}, \param{const wxString\&}{ dst}}
202
203Rename the specified {\it src} element to {\it dst}. Returns true if successful.
204
205% ----------------------------------------------------------------------------
206
207
208\membersection{wxFTP::RmFile}\label{wxftprmfile}
209
210\func{bool}{RmFile}{\param{const wxString\&}{ path}}
211
212Delete the file specified by {\it path}. Returns true if successful.
213
214% ----------------------------------------------------------------------------
215
216
217\membersection{wxFTP::SetAscii}\label{wxftpsetascii}
218
219\func{bool}{SetAscii}{\void}
220
221Sets the transfer mode to ASCII. It will be used for the next transfer.
222
223
224\membersection{wxFTP::SetBinary}\label{wxftpsetbinary}
225
226\func{bool}{SetBinary}{\void}
227
228Sets the transfer mode to binary (IMAGE). It will be used for the next transfer.
229
230
231\membersection{wxFTP::SetPassive}\label{wxftpsetpassive}
232
233\func{void}{SetPassive}{\param{bool }{pasv}}
234
235If \arg{pasv} is \true, passive connection to the FTP server is used. This is
236the default as it works with practically all firewalls. If the server doesn't
237support passive move, you may call this function with \false argument to use
238active connection.
239
240
241\membersection{wxFTP::SetTransferMode}\label{wxftpsettransfermode}
242
243\func{bool}{SetTransferMode}{\param{TransferMode }{mode}}
244
245Sets the transfer mode to the specified one. It will be used for the next
246transfer.
247
248If this function is never called, binary transfer mode is used by default.
249
250% ----------------------------------------------------------------------------
251
252
253\membersection{wxFTP::SetUser}\label{wxftpsetuser}
254
255\func{void}{SetUser}{\param{const wxString\&}{ user}}
256
257Sets the user name to be sent to the FTP server to be allowed to log in.
258
259\wxheading{Default value}
260
261The default value of the user name is "anonymous".
262
263\wxheading{Remark}
264
265This parameter can be included in a URL if you want to use the URL manager.
266For example, you can use: "ftp://a\_user:a\_password@a.host:service/a\_directory/a\_file"
267to specify a user and a password.
268
269
270\membersection{wxFTP::SetPassword}\label{wxftpsetpassword}
271
272\func{void}{SetPassword}{\param{const wxString\&}{ passwd}}
273
274Sets the password to be sent to the FTP server to be allowed to log in.
275
276\wxheading{Default value}
277
278The default value of the user name is your email address. For example, it could
279be "username@userhost.domain". This password is built by getting the current
280user name and the host name of the local machine from the system.
281
282\wxheading{Remark}
283
284This parameter can be included in a URL if you want to use the URL manager.
285For example, you can use: "ftp://a\_user:a\_password@a.host:service/a\_directory/a\_file"
286to specify a user and a password.
287
288% ----------------------------------------------------------------------------
289
290
291\membersection{wxFTP::FileExists}\label{wxftpfileexists}
292
293\func{bool}{FileExists}{\param{const wxString\&}{ filename}}
294
295Returns \true if the given remote file exists, \false otherwise.
296
297
298\membersection{wxFTP::GetFileSize}\label{wxftpgetfilesize}
299
300\func{int}{GetFileSize}{\param{const wxString\&}{ filename}}
301
302Returns the file size in bytes or $-1$ if the file doesn't exist or the size
303couldn't be determined. Notice that this size can be approximative size only
304and shouldn't be used for allocating the buffer in which the remote file is
305copied, for example.
306
307
308\membersection{wxFTP::GetDirList}\label{wxftpgetdirlist}
309
310\func{bool}{GetDirList}{\param{wxArrayString\& }{files}, \param{const wxString\&}{ wildcard = ""}}
311
312The GetList function is quite low-level. It returns the list of the files in
313the current directory. The list can be filtered using the {\it wildcard} string.
314If {\it wildcard} is empty (default), it will return all files in directory.
315
316The form of the list can change from one peer system to another. For example,
317for a UNIX peer system, it will look like this:
318
319\begin{verbatim}
320-r--r--r-- 1 guilhem lavaux 12738 Jan 16 20:17 cmndata.cpp
321-r--r--r-- 1 guilhem lavaux 10866 Jan 24 16:41 config.cpp
322-rw-rw-rw- 1 guilhem lavaux 29967 Dec 21 19:17 cwlex_yy.c
323-rw-rw-rw- 1 guilhem lavaux 14342 Jan 22 19:51 cwy_tab.c
324-r--r--r-- 1 guilhem lavaux 13890 Jan 29 19:18 date.cpp
325-r--r--r-- 1 guilhem lavaux 3989 Feb 8 19:18 datstrm.cpp
326\end{verbatim}
327
328But on Windows system, it will look like this:
329
330\begin{verbatim}
331winamp~1 exe 520196 02-25-1999 19:28 winamp204.exe
332 1 file(s) 520 196 bytes
333\end{verbatim}
334
335Return value: true if the file list was successfully retrieved, false
336otherwise.
337
338\wxheading{See also}
339
340\helpref{GetFilesList}{wxftpgetfileslist}
341
342
343\membersection{wxFTP::GetFilesList}\label{wxftpgetfileslist}
344
345\func{bool}{GetFilesList}{\param{wxArrayString\& }{files}, \param{const wxString\&}{ wildcard = ""}}
346
347This function returns the computer-parsable list of the files in the current
348directory (optionally only of the files matching the {\it wildcard}, all files
349by default). This list always has the same format and contains one full
350(including the directory path) file name per line.
351
352Return value: true if the file list was successfully retrieved, false
353otherwise.
354
355% ----------------------------------------------------------------------------
356
357
358\membersection{wxFTP::GetOutputStream}\label{wxftpgetoutputstream}
359
360\func{wxOutputStream *}{GetOutputStream}{\param{const wxString\&}{ file}}
361
362Initializes an output stream to the specified {\it file}. The returned
363stream has all but the seek functionality of wxStreams. When the user finishes
364writing data, he has to delete the stream to close it.
365
366\wxheading{Return value}
367
368An initialized write-only stream.
369
370\wxheading{See also}
371
372\helpref{wxOutputStream}{wxoutputstream}
373
374% ----------------------------------------------------------------------------
375
376
377\membersection{wxFTP::GetInputStream}\label{wxftpgetinputstream}
378
379\func{wxInputStream *}{GetInputStream}{\param{const wxString\&}{ path}}
380
381Creates a new input stream on the specified path. You can use all but the seek
382functionality of wxStream. Seek isn't available on all streams. For example,
383HTTP or FTP streams do not deal with it. Other functions like Tell
384are not available for this sort of stream, at present.
385You will be notified when the EOF is reached by an error.
386
387\wxheading{Return value}
388
389Returns NULL if an error occurred (it could be a network failure or the fact
390that the file doesn't exist).
391
392Returns the initialized stream. You will have to delete it yourself when you
393don't need it anymore. The destructor closes the DATA stream connection but
394will leave the COMMAND stream connection opened. It means that you can still
395send new commands without reconnecting.
396
397\wxheading{Example of a standalone connection (without wxURL)}
398
399\begin{verbatim}
400 wxFTP ftp;
401 wxInputStream *in_stream;
402 char *data;
403
404 ftp.Connect("a.host.domain");
405 ftp.ChDir("a_directory");
406 in_stream = ftp.GetInputStream("a_file_to_get");
407
408 data = new char[in_stream->GetSize()];
409
410 in_stream->Read(data, in_stream->GetSize());
411 if (in_stream->LastError() != wxStream_NOERROR) {
412 // Do something.
413 }
414
415 delete in_stream; /* Close the DATA connection */
416
417 ftp.Close(); /* Close the COMMAND connection */
418\end{verbatim}
419
420\wxheading{See also}
421
422\helpref{wxInputStream}{wxinputstream}
423