1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxFTP documentation
4 %% Author: Guilhem Lavaux, Vadim Zeitlin
8 %% Copyright: (c) wxWindows 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("wxWindows-
4.2.0.tar.gz");
43 wxLogError("Coudln't get file");
47 size_t size = in->StreamSize();
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
}
92 \wxheading{Include files
}
98 \helpref{wxSocketBase
}{wxsocketbase
}
100 % ----------------------------------------------------------------------------
102 % ----------------------------------------------------------------------------
104 \latexignore{\rtfignore{\wxheading{Members
}}}
106 \membersection{wxFTP::wxFTP
}
108 \func{}{wxFTP
}{\void}
112 \membersection{wxFTP::
\destruct{wxFTP
}}
114 \func{}{\destruct{wxFTP
}}{\void}
116 Destructor will close the connection if connected.
118 \membersection{wxFTP::CheckCommand
}
120 \func{bool
}{CheckCommand
}{\param{const wxString\&
}{ command
},
\param{char
}{ret
}}
122 Send the specified
{\it command
} to the FTP server.
{\it ret
} specifies
125 \wxheading{Return value
}
127 TRUE if the command has been sent successfully, else FALSE.
129 \membersection{wxFTP::SendCommand
}\label{wxftpsendcommand
}
131 \func{char
}{SendCommand
}{\param{const wxString\&
}{ command
}}
133 Send the specified
{\it command
} to the FTP server and return the first
134 character of the return code.
136 \membersection{wxFTP::GetLastResult
}
138 \func{const wxString\&
}{GetLastResult
}{\void}
140 Returns the last command result, i.e. the full server reply for the last
143 % ----------------------------------------------------------------------------
145 \membersection{wxFTP::ChDir
}
147 \func{bool
}{ChDir
}{\param{const wxString\&
}{ dir
}}
149 Change the current FTP working directory.
150 Returns TRUE if successful.
152 \membersection{wxFTP::MkDir
}
154 \func{bool
}{MkDir
}{\param{const wxString\&
}{ dir
}}
156 Create the specified directory in the current FTP working directory.
157 Returns TRUE if successful.
159 \membersection{wxFTP::RmDir
}
161 \func{bool
}{RmDir
}{\param{const wxString\&
}{ dir
}}
163 Remove the specified directory from the current FTP working directory.
164 Returns TRUE if successful.
166 \membersection{wxFTP::Pwd
}
168 \func{wxString
}{Pwd
}{\void}
170 Returns the current FTP working directory.
172 % ----------------------------------------------------------------------------
174 \membersection{wxFTP::Rename
}
176 \func{bool
}{Rename
}{\param{const wxString\&
}{ src
},
\param{const wxString\&
}{ dst
}}
178 Rename the specified
{\it src
} element to
{\it dst
}. Returns TRUE if successful.
180 % ----------------------------------------------------------------------------
182 \membersection{wxFTP::RmFile
}
184 \func{bool
}{RmFile
}{\param{const wxString\&
}{ path
}}
186 Delete the file specified by
{\it path
}. Returns TRUE if successful.
188 % ----------------------------------------------------------------------------
190 \membersection{wxFTP::SetAscii
}
192 \func{bool
}{SetAscii
}{\void}
194 Sets the transfer mode to ASCII. It will be used for the next transfer.
196 \membersection{wxFTP::SetBinary
}
198 \func{bool
}{SetBinary
}{\void}
200 Sets the transfer mode to binary (IMAGE). It will be used for the next transfer.
202 \membersection{wxFTP::SetTransferMode
}
204 \func{bool
}{SetTransferMode
}{\param{TransferMode
}{mode
}}
206 Sets the transfer mode to the specified one. It will be used for the next
209 If this function is never called, binary transfer mode is used by default.
211 % ----------------------------------------------------------------------------
213 \membersection{wxFTP::SetUser
}
215 \func{void
}{SetUser
}{\param{const wxString\&
}{ user
}}
217 Sets the user name to be sent to the FTP server to be allowed to log in.
219 \wxheading{Default value
}
221 The default value of the user name is "anonymous".
225 This parameter can be included in a URL if you want to use the URL manager.
226 For example, you can use: "ftp://a
\_user:a
\_password@a.host:service/a
\_directory/a
\_file"
227 to specify a user and a password.
229 \membersection{wxFTP::SetPassword
}
231 \func{void
}{SetPassword
}{\param{const wxString\&
}{ passwd
}}
233 Sets the password to be sent to the FTP server to be allowed to log in.
235 \wxheading{Default value
}
237 The default value of the user name is your email address. For example, it could
238 be "username@userhost.domain". This password is built by getting the current
239 user name and the host name of the local machine from the system.
243 This parameter can be included in a URL if you want to use the URL manager.
244 For example, you can use: "ftp://a
\_user:a
\_password@a.host:service/a
\_directory/a
\_file"
245 to specify a user and a password.
247 % ----------------------------------------------------------------------------
249 \membersection{wxFTP::GetDirList
}\label{wxftpgetdirlist
}
251 \func{bool
}{GetDirList
}{\param{wxArrayString\&
}{files
},
\param{const wxString\&
}{ wildcard = ""
}}
253 The GetList function is quite low-level. It returns the list of the files in
254 the current directory. The list can be filtered using the
{\it wildcard
} string.
255 If
{\it wildcard
} is empty (default), it will return all files in directory.
257 The form of the list can change from one peer system to another. For example,
258 for a UNIX peer system, it will look like this:
261 -r--r--r--
1 guilhem lavaux
12738 Jan
16 20:
17 cmndata.cpp
262 -r--r--r--
1 guilhem lavaux
10866 Jan
24 16:
41 config.cpp
263 -rw-rw-rw-
1 guilhem lavaux
29967 Dec
21 19:
17 cwlex_yy.c
264 -rw-rw-rw-
1 guilhem lavaux
14342 Jan
22 19:
51 cwy_tab.c
265 -r--r--r--
1 guilhem lavaux
13890 Jan
29 19:
18 date.cpp
266 -r--r--r--
1 guilhem lavaux
3989 Feb
8 19:
18 datstrm.cpp
269 But on Windows system, it will look like this:
272 winamp~
1 exe
520196 02-
25-
1999 19:
28 winamp204.exe
273 1 file(s)
520 196 bytes
276 Return value: TRUE if the file list was successfully retrieved, FALSE
281 \helpref{GetFilesList
}{wxftpgetfileslist
}
283 \membersection{wxFTP::GetFilesList
}\label{wxftpgetfileslist
}
285 \func{bool
}{GetFilesList
}{\param{wxArrayString\&
}{files
},
\param{const wxString\&
}{ wildcard = ""
}}
287 This function returns the computer-parsable list of the files in the current
288 directory (optionally only of the files matching the
{\it wildcard
}, all files
289 by default). This list always has the same format and contains one full
290 (including the directory path) file name per line.
292 Return value: TRUE if the file list was successfully retrieved, FALSE
295 % ----------------------------------------------------------------------------
297 \membersection{wxFTP::GetOutputStream
}
299 \func{wxOutputStream *
}{GetOutputStream
}{\param{const wxString\&
}{ file
}}
301 Initializes an output stream to the specified
{\it file
}. The returned
302 stream has all but the seek functionality of wxStreams. When the user finishes
303 writing data, he has to delete the stream to close it.
305 \wxheading{Return value
}
307 An initialized write-only stream.
311 \helpref{wxOutputStream
}{wxoutputstream
}
313 % ----------------------------------------------------------------------------
315 \membersection{wxFTP::GetInputStream
}\label{wxftpgetinput
}
317 \func{wxInputStream *
}{GetInputStream
}{\param{const wxString\&
}{ path
}}
319 Creates a new input stream on the the specified path. You can use all but the seek
320 functionality of wxStream. Seek isn't available on all streams. For example,
321 http or ftp streams do not deal with it. Other functions like Tell
322 are not available for this sort of stream, at present.
323 You will be notified when the EOF is reached by an error.
325 \wxheading{Return value
}
327 Returns NULL if an error occurred (it could be a network failure or the fact
328 that the file doesn't exist).
330 Returns the initialized stream. You will have to delete it yourself when you
331 don't need it anymore. The destructor closes the DATA stream connection but
332 will leave the COMMAND stream connection opened. It means that you can still
333 send new commands without reconnecting.
335 \wxheading{Example of a standalone connection (without wxURL)
}
339 wxInputStream *in_stream;
342 ftp.Connect("a.host.domain");
343 ftp.ChDir("a_directory");
344 in_stream = ftp.GetInputStream("a_file_to_get");
346 data = new char
[in_stream->StreamSize()
];
348 in_stream->Read(data, in_stream->StreamSize());
349 if (in_stream->LastError() != wxStream_NOERROR)
{
353 delete in_stream; /* Close the DATA connection */
355 ftp.Close(); /* Close the COMMAND connection */
360 \helpref{wxInputStream
}{wxinputstream
}