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