]>
git.saurik.com Git - wxWidgets.git/blob - interface/protocol/ftp.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: protocol/ftp.h
3 // Purpose: interface of wxFTP
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 Transfer modes used by wxFTP.
14 NONE
, //!< not set by user explicitly.
21 @headerfile ftp.h wx/protocol/ftp.h
23 wxFTP can be used to establish a connection to an FTP server and perform all the
24 usual operations. Please consult the RFC 959 for more details about the FTP
27 To use a command which doesn't involve file transfer (i.e. directory oriented
28 commands) you just need to call a corresponding member function or use the
29 generic wxFTP::SendCommand() method.
30 However to actually transfer files you just get or give a stream to or from this
31 class and the actual data are read or written using the usual stream methods.
33 Example of using wxFTP for file downloading:
38 // if you don't use these lines anonymous login will be used
40 ftp.SetPassword("password");
42 if ( !ftp.Connect("ftp.wxwindows.org") )
44 wxLogError("Couldn't connect");
49 wxInputStream *in = ftp.GetInputStream("wxWidgets-4.2.0.tar.gz");
52 wxLogError("Coudln't get file");
56 size_t size = in-GetSize();
57 char *data = new char[size];
58 if ( !in->Read(data, size) )
60 wxLogError("Read error");
64 // file data is in the buffer
73 To upload a file you would do (assuming the connection to the server was opened
77 wxOutputStream *out = ftp.GetOutputStream("filename");
80 out->Write(...); // your data
90 class wxFTP
: public wxProtocol
99 Destructor will close the connection if connected.
104 Aborts the download currently in process, returns @true if ok, @false
105 if an error occurred.
110 Change the current FTP working directory.
111 Returns @true if successful.
113 bool ChDir(const wxString
& dir
);
116 Send the specified @a command to the FTP server. @a ret specifies
119 @returns @true if the command has been sent successfully, else @false.
121 bool CheckCommand(const wxString
& command
, char ret
);
124 Returns @true if the given remote file exists, @false otherwise.
126 bool FileExists(const wxString
& filename
);
129 The GetList() function is quite low-level. It returns the list of the files in
130 the current directory. The list can be filtered using the @a wildcard string.
132 If @a wildcard is empty (default), it will return all files in directory.
133 The form of the list can change from one peer system to another. For example,
134 for a UNIX peer system, it will look like this:
137 -r--r--r-- 1 guilhem lavaux 12738 Jan 16 20:17 cmndata.cpp
138 -r--r--r-- 1 guilhem lavaux 10866 Jan 24 16:41 config.cpp
139 -rw-rw-rw- 1 guilhem lavaux 29967 Dec 21 19:17 cwlex_yy.c
140 -rw-rw-rw- 1 guilhem lavaux 14342 Jan 22 19:51 cwy_tab.c
141 -r--r--r-- 1 guilhem lavaux 13890 Jan 29 19:18 date.cpp
142 -r--r--r-- 1 guilhem lavaux 3989 Feb 8 19:18 datstrm.cpp
145 But on Windows system, it will look like this:
148 winamp~1 exe 520196 02-25-1999 19:28 winamp204.exe
149 1 file(s) 520 196 bytes
152 @return @true if the file list was successfully retrieved, @false otherwise.
156 bool GetDirList(wxArrayString
& files
,
157 const wxString
& wildcard
= "");
160 Returns the file size in bytes or -1 if the file doesn't exist or the size
161 couldn't be determined.
163 Notice that this size can be approximative size only and shouldn't be used
164 for allocating the buffer in which the remote file is copied, for example.
166 int GetFileSize(const wxString
& filename
);
169 This function returns the computer-parsable list of the files in the current
170 directory (optionally only of the files matching the @e wildcard, all files
173 This list always has the same format and contains one full (including the
174 directory path) file name per line.
176 @returns @true if the file list was successfully retrieved, @false otherwise.
180 bool GetFilesList(wxArrayString
& files
,
181 const wxString
& wildcard
= "");
184 Creates a new input stream on the specified path.
186 You can use all but the seek functionality of wxStreamBase.
187 wxStreamBase::Seek() isn't available on all streams. For example, HTTP or FTP
188 streams do not deal with it. Other functions like wxStreamBase::Tell() are
189 not available for this sort of stream, at present.
191 You will be notified when the EOF is reached by an error.
193 @returns Returns @NULL if an error occurred (it could be a network failure
194 or the fact that the file doesn't exist).
196 wxInputStream
* GetInputStream(const wxString
& path
);
199 Returns the last command result, i.e. the full server reply for the last command.
201 const wxString
GetLastResult();
204 Initializes an output stream to the specified @e file.
206 The returned stream has all but the seek functionality of wxStreams.
207 When the user finishes writing data, he has to delete the stream to close it.
209 @returns An initialized write-only stream.
213 wxOutputStream
* GetOutputStream(const wxString
& file
);
216 Create the specified directory in the current FTP working directory.
217 Returns @true if successful.
219 bool MkDir(const wxString
& dir
);
222 Returns the current FTP working directory.
227 Rename the specified @a src element to @e dst. Returns @true if successful.
229 bool Rename(const wxString
& src
, const wxString
& dst
);
232 Remove the specified directory from the current FTP working directory.
233 Returns @true if successful.
235 bool RmDir(const wxString
& dir
);
238 Delete the file specified by @e path. Returns @true if successful.
240 bool RmFile(const wxString
& path
);
243 Send the specified @a command to the FTP server and return the first
244 character of the return code.
246 char SendCommand(const wxString
& command
);
249 Sets the transfer mode to ASCII. It will be used for the next transfer.
254 Sets the transfer mode to binary (IMAGE). It will be used for the next transfer.
259 If @a pasv is @true, passive connection to the FTP server is used.
261 This is the default as it works with practically all firewalls.
262 If the server doesn't support passive move, you may call this function with
263 @false argument to use active connection.
265 void SetPassive(bool pasv
);
268 Sets the password to be sent to the FTP server to be allowed to log in.
270 void SetPassword(const wxString
& passwd
);
273 Sets the transfer mode to the specified one. It will be used for the next
276 If this function is never called, binary transfer mode is used by default.
278 bool SetTransferMode(TransferMode mode
);
281 Sets the user name to be sent to the FTP server to be allowed to log in.
283 void SetUser(const wxString
& user
);