]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/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.
22 wxFTP can be used to establish a connection to an FTP server and perform all the
23 usual operations. Please consult the RFC 959 for more details about the FTP
26 To use a command which doesn't involve file transfer (i.e. directory oriented
27 commands) you just need to call a corresponding member function or use the
28 generic wxFTP::SendCommand() method.
29 However to actually transfer files you just get or give a stream to or from this
30 class and the actual data are read or written using the usual stream methods.
32 Example of using wxFTP for file downloading:
37 // if you don't use these lines anonymous login will be used
39 ftp.SetPassword("password");
41 if ( !ftp.Connect("ftp.wxwindows.org") )
43 wxLogError("Couldn't connect");
48 wxInputStream *in = ftp.GetInputStream("wxWidgets-4.2.0.tar.gz");
51 wxLogError("Coudln't get file");
55 size_t size = in-GetSize();
56 char *data = new char[size];
57 if ( !in->Read(data, size) )
59 wxLogError("Read error");
63 // file data is in the buffer
72 To upload a file you would do (assuming the connection to the server was opened
76 wxOutputStream *out = ftp.GetOutputStream("filename");
79 out->Write(...); // your data
89 class wxFTP
: public wxProtocol
98 Destructor will close the connection if connected.
103 Aborts the download currently in process, returns @true if ok, @false
104 if an error occurred.
106 virtual bool Abort();
109 Change the current FTP working directory.
110 Returns @true if successful.
112 bool ChDir(const wxString
& dir
);
115 Send the specified @a command to the FTP server. @a ret specifies
118 @return @true if the command has been sent successfully, else @false.
120 bool CheckCommand(const wxString
& command
, char ret
);
123 Returns @true if the given remote file exists, @false otherwise.
125 bool FileExists(const wxString
& filename
);
128 The GetList() function is quite low-level. It returns the list of the files in
129 the current directory. The list can be filtered using the @a wildcard string.
131 If @a wildcard is empty (default), it will return all files in directory.
132 The form of the list can change from one peer system to another. For example,
133 for a UNIX peer system, it will look like this:
136 -r--r--r-- 1 guilhem lavaux 12738 Jan 16 20:17 cmndata.cpp
137 -r--r--r-- 1 guilhem lavaux 10866 Jan 24 16:41 config.cpp
138 -rw-rw-rw- 1 guilhem lavaux 29967 Dec 21 19:17 cwlex_yy.c
139 -rw-rw-rw- 1 guilhem lavaux 14342 Jan 22 19:51 cwy_tab.c
140 -r--r--r-- 1 guilhem lavaux 13890 Jan 29 19:18 date.cpp
141 -r--r--r-- 1 guilhem lavaux 3989 Feb 8 19:18 datstrm.cpp
144 But on Windows system, it will look like this:
147 winamp~1 exe 520196 02-25-1999 19:28 winamp204.exe
148 1 file(s) 520 196 bytes
151 @return @true if the file list was successfully retrieved, @false otherwise.
155 bool GetDirList(wxArrayString
& files
,
156 const wxString
& wildcard
= wxEmptyString
);
159 Returns the file size in bytes or -1 if the file doesn't exist or the size
160 couldn't be determined.
162 Notice that this size can be approximative size only and shouldn't be used
163 for allocating the buffer in which the remote file is copied, for example.
165 int GetFileSize(const wxString
& filename
);
168 This function returns the computer-parsable list of the files in the current
169 directory (optionally only of the files matching the @e wildcard, all files
172 This list always has the same format and contains one full (including the
173 directory path) file name per line.
175 @return @true if the file list was successfully retrieved, @false otherwise.
179 bool GetFilesList(wxArrayString
& files
,
180 const wxString
& wildcard
= wxEmptyString
);
183 Creates a new input stream on the specified path.
185 You can use all but the seek functionality of wxStreamBase.
186 wxStreamBase::Seek() isn't available on all streams. For example, HTTP or FTP
187 streams do not deal with it. Other functions like wxStreamBase::Tell() are
188 not available for this sort of stream, at present.
190 You will be notified when the EOF is reached by an error.
192 @return Returns @NULL if an error occurred (it could be a network failure
193 or the fact that the file doesn't exist).
195 virtual wxInputStream
* GetInputStream(const wxString
& path
);
198 Returns the last command result, i.e. the full server reply for the last command.
200 const wxString
& GetLastResult();
203 Initializes an output stream to the specified @e file.
205 The returned stream has all but the seek functionality of wxStreams.
206 When the user finishes writing data, he has to delete the stream to close it.
208 @return An initialized write-only stream.
212 virtual wxOutputStream
* GetOutputStream(const wxString
& file
);
215 Create the specified directory in the current FTP working directory.
216 Returns @true if successful.
218 bool MkDir(const wxString
& dir
);
221 Returns the current FTP working directory.
226 Rename the specified @a src element to @e dst. Returns @true if successful.
228 bool Rename(const wxString
& src
, const wxString
& dst
);
231 Remove the specified directory from the current FTP working directory.
232 Returns @true if successful.
234 bool RmDir(const wxString
& dir
);
237 Delete the file specified by @e path. Returns @true if successful.
239 bool RmFile(const wxString
& path
);
242 Send the specified @a command to the FTP server and return the first
243 character of the return code.
245 char SendCommand(const wxString
& command
);
248 Sets the transfer mode to ASCII. It will be used for the next transfer.
253 Sets the transfer mode to binary (IMAGE). It will be used for the next transfer.
258 If @a pasv is @true, passive connection to the FTP server is used.
260 This is the default as it works with practically all firewalls.
261 If the server doesn't support passive move, you may call this function with
262 @false argument to use active connection.
264 void SetPassive(bool pasv
);
267 Sets the password to be sent to the FTP server to be allowed to log in.
269 virtual void SetPassword(const wxString
& passwd
);
272 Sets the transfer mode to the specified one. It will be used for the next
275 If this function is never called, binary transfer mode is used by default.
277 bool SetTransferMode(TransferMode mode
);
280 Sets the user name to be sent to the FTP server to be allowed to log in.
282 virtual void SetUser(const wxString
& user
);