1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxFTP documentation
4 %% Author: Guilhem Lavaux, Vadim Zeitlin
8 %% Copyright: (c) wxWidgets team
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxFTP
}}\label{wxftp
}
14 wxFTP can be used to establish a connection to an FTP server and perform all the
15 usual operations. Please consult the RFC
959 for more details about the FTP
18 To use a commands which doesn't involve file transfer (i.e. directory oriented
19 commands) you just need to call a corresponding member function or use the
20 generic
\helpref{SendCommand
}{wxftpsendcommand
} method. However to actually
21 transfer files you just get or give a stream to or from this class and the
22 actual data are read or written using the usual stream methods.
24 Example of using wxFTP for file downloading:
29 // if you don't use these lines anonymous login will be used
31 ftp.SetPassword("password");
33 if ( !ftp.Connect("ftp.wxwindows.org") )
35 wxLogError("Couldn't connect");
40 wxInputStream *in = ftp.GetInputStream("wxWidgets-
4.2.0.tar.gz");
43 wxLogError("Coudln't get file");
47 size_t size = in->GetSize();
48 char *data = new char
[size
];
49 if ( !in->Read(data, size) )
51 wxLogError("Read error");
55 // file data is in the buffer
64 To upload a file you would do (assuming the connection to the server was opened
68 wxOutputStream *out = ftp.GetOutputStream("filename");
71 out->Write(...); // your data
78 wxFTP defines constants corresponding to the two supported transfer modes:
88 \wxheading{Derived from
}
90 \helpref{wxProtocol
}{wxprotocol
}\\
91 \helpref{wxSocketClient
}{wxsocketclient
}\\
92 \helpref{wxSocketBase
}{wxsocketbase
}\\
93 \helpref{wxObject
}{wxobject
}
95 \wxheading{Include files
}
101 \helpref{wxNet
}{librarieslist
}
105 \helpref{wxSocketBase
}{wxsocketbase
}
107 % ----------------------------------------------------------------------------
109 % ----------------------------------------------------------------------------
111 \latexignore{\rtfignore{\wxheading{Members
}}}
114 \membersection{wxFTP::wxFTP
}\label{wxftpctor
}
116 \func{}{wxFTP
}{\void}
121 \membersection{wxFTP::
\destruct{wxFTP
}}\label{wxftpdtor
}
123 \func{}{\destruct{wxFTP
}}{\void}
125 Destructor will close the connection if connected.
128 \membersection{wxFTP::Abort
}\label{wxftpabort
}
130 \func{bool
}{Abort
}{\void}
132 Aborts the download currently in process, returns
\true if ok,
\false
133 if an error occurred.
136 \membersection{wxFTP::CheckCommand
}\label{wxftpcheckcommand
}
138 \func{bool
}{CheckCommand
}{\param{const wxString\&
}{ command
},
\param{char
}{ret
}}
140 Send the specified
{\it command
} to the FTP server.
{\it ret
} specifies
143 \wxheading{Return value
}
145 true if the command has been sent successfully, else false.
148 \membersection{wxFTP::SendCommand
}\label{wxftpsendcommand
}
150 \func{char
}{SendCommand
}{\param{const wxString\&
}{ command
}}
152 Send the specified
{\it command
} to the FTP server and return the first
153 character of the return code.
156 \membersection{wxFTP::GetLastResult
}\label{wxftpgetlastresult
}
158 \func{const wxString\&
}{GetLastResult
}{\void}
160 Returns the last command result, i.e. the full server reply for the last
163 % ----------------------------------------------------------------------------
166 \membersection{wxFTP::ChDir
}\label{wxftpchdir
}
168 \func{bool
}{ChDir
}{\param{const wxString\&
}{ dir
}}
170 Change the current FTP working directory.
171 Returns true if successful.
174 \membersection{wxFTP::MkDir
}\label{wxftpmkdir
}
176 \func{bool
}{MkDir
}{\param{const wxString\&
}{ dir
}}
178 Create the specified directory in the current FTP working directory.
179 Returns true if successful.
182 \membersection{wxFTP::RmDir
}\label{wxftprmdir
}
184 \func{bool
}{RmDir
}{\param{const wxString\&
}{ dir
}}
186 Remove the specified directory from the current FTP working directory.
187 Returns true if successful.
190 \membersection{wxFTP::Pwd
}\label{wxftppwd
}
192 \func{wxString
}{Pwd
}{\void}
194 Returns the current FTP working directory.
196 % ----------------------------------------------------------------------------
199 \membersection{wxFTP::Rename
}\label{wxftprename
}
201 \func{bool
}{Rename
}{\param{const wxString\&
}{ src
},
\param{const wxString\&
}{ dst
}}
203 Rename the specified
{\it src
} element to
{\it dst
}. Returns true if successful.
205 % ----------------------------------------------------------------------------
208 \membersection{wxFTP::RmFile
}\label{wxftprmfile
}
210 \func{bool
}{RmFile
}{\param{const wxString\&
}{ path
}}
212 Delete the file specified by
{\it path
}. Returns true if successful.
214 % ----------------------------------------------------------------------------
217 \membersection{wxFTP::SetAscii
}\label{wxftpsetascii
}
219 \func{bool
}{SetAscii
}{\void}
221 Sets the transfer mode to ASCII. It will be used for the next transfer.
224 \membersection{wxFTP::SetBinary
}\label{wxftpsetbinary
}
226 \func{bool
}{SetBinary
}{\void}
228 Sets the transfer mode to binary (IMAGE). It will be used for the next transfer.
231 \membersection{wxFTP::SetPassive
}\label{wxftpsetpassive
}
233 \func{void
}{SetPassive
}{\param{bool
}{pasv
}}
235 If
\arg{pasv
} is
\true, passive connection to the FTP server is used. This is
236 the default as it works with practically all firewalls. If the server doesn't
237 support passive move, you may call this function with
\false argument to use
241 \membersection{wxFTP::SetTransferMode
}\label{wxftpsettransfermode
}
243 \func{bool
}{SetTransferMode
}{\param{TransferMode
}{mode
}}
245 Sets the transfer mode to the specified one. It will be used for the next
248 If this function is never called, binary transfer mode is used by default.
250 % ----------------------------------------------------------------------------
253 \membersection{wxFTP::SetUser
}\label{wxftpsetuser
}
255 \func{void
}{SetUser
}{\param{const wxString\&
}{ user
}}
257 Sets the user name to be sent to the FTP server to be allowed to log in.
259 \wxheading{Default value
}
261 The default value of the user name is "anonymous".
265 This parameter can be included in a URL if you want to use the URL manager.
266 For example, you can use: "ftp://a
\_user:a
\_password@a.host:service/a
\_directory/a
\_file"
267 to specify a user and a password.
270 \membersection{wxFTP::SetPassword
}\label{wxftpsetpassword
}
272 \func{void
}{SetPassword
}{\param{const wxString\&
}{ passwd
}}
274 Sets the password to be sent to the FTP server to be allowed to log in.
276 \wxheading{Default value
}
278 The default value of the user name is your email address. For example, it could
279 be "username@userhost.domain". This password is built by getting the current
280 user name and the host name of the local machine from the system.
284 This parameter can be included in a URL if you want to use the URL manager.
285 For example, you can use: "ftp://a
\_user:a
\_password@a.host:service/a
\_directory/a
\_file"
286 to specify a user and a password.
288 % ----------------------------------------------------------------------------
291 \membersection{wxFTP::FileExists
}\label{wxftpfileexists
}
293 \func{bool
}{FileExists
}{\param{const wxString\&
}{ filename
}}
295 Returns
\true if the given remote file exists,
\false otherwise.
298 \membersection{wxFTP::GetFileSize
}\label{wxftpgetfilesize
}
300 \func{int
}{GetFileSize
}{\param{const wxString\&
}{ filename
}}
302 Returns the file size in bytes or $-
1$ if the file doesn't exist or the size
303 couldn't be determined. Notice that this size can be approximative size only
304 and shouldn't be used for allocating the buffer in which the remote file is
308 \membersection{wxFTP::GetDirList
}\label{wxftpgetdirlist
}
310 \func{bool
}{GetDirList
}{\param{wxArrayString\&
}{files
},
\param{const wxString\&
}{ wildcard = ""
}}
312 The GetList function is quite low-level. It returns the list of the files in
313 the current directory. The list can be filtered using the
{\it wildcard
} string.
314 If
{\it wildcard
} is empty (default), it will return all files in directory.
316 The form of the list can change from one peer system to another. For example,
317 for a UNIX peer system, it will look like this:
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
328 But on Windows system, it will look like this:
331 winamp~
1 exe
520196 02-
25-
1999 19:
28 winamp204.exe
332 1 file(s)
520 196 bytes
335 Return value: true if the file list was successfully retrieved, false
340 \helpref{GetFilesList
}{wxftpgetfileslist
}
343 \membersection{wxFTP::GetFilesList
}\label{wxftpgetfileslist
}
345 \func{bool
}{GetFilesList
}{\param{wxArrayString\&
}{files
},
\param{const wxString\&
}{ wildcard = ""
}}
347 This function returns the computer-parsable list of the files in the current
348 directory (optionally only of the files matching the
{\it wildcard
}, all files
349 by default). This list always has the same format and contains one full
350 (including the directory path) file name per line.
352 Return value: true if the file list was successfully retrieved, false
355 % ----------------------------------------------------------------------------
358 \membersection{wxFTP::GetOutputStream
}\label{wxftpgetoutputstream
}
360 \func{wxOutputStream *
}{GetOutputStream
}{\param{const wxString\&
}{ file
}}
362 Initializes an output stream to the specified
{\it file
}. The returned
363 stream has all but the seek functionality of wxStreams. When the user finishes
364 writing data, he has to delete the stream to close it.
366 \wxheading{Return value
}
368 An initialized write-only stream.
372 \helpref{wxOutputStream
}{wxoutputstream
}
374 % ----------------------------------------------------------------------------
377 \membersection{wxFTP::GetInputStream
}\label{wxftpgetinputstream
}
379 \func{wxInputStream *
}{GetInputStream
}{\param{const wxString\&
}{ path
}}
381 Creates a new input stream on the specified path. You can use all but the seek
382 functionality of wxStream. Seek isn't available on all streams. For example,
383 HTTP or FTP streams do not deal with it. Other functions like Tell
384 are not available for this sort of stream, at present.
385 You will be notified when the EOF is reached by an error.
387 \wxheading{Return value
}
389 Returns NULL if an error occurred (it could be a network failure or the fact
390 that the file doesn't exist).
392 Returns the initialized stream. You will have to delete it yourself when you
393 don't need it anymore. The destructor closes the DATA stream connection but
394 will leave the COMMAND stream connection opened. It means that you can still
395 send new commands without reconnecting.
397 \wxheading{Example of a standalone connection (without wxURL)
}
401 wxInputStream *in_stream;
404 ftp.Connect("a.host.domain");
405 ftp.ChDir("a_directory");
406 in_stream = ftp.GetInputStream("a_file_to_get");
408 data = new char
[in_stream->GetSize()
];
410 in_stream->Read(data, in_stream->GetSize());
411 if (in_stream->LastError() != wxStream_NOERROR)
{
415 delete in_stream; /* Close the DATA connection */
417 ftp.Close(); /* Close the COMMAND connection */
422 \helpref{wxInputStream
}{wxinputstream
}