]>
git.saurik.com Git - wxWidgets.git/blob - interface/protocol/ftp.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: protocol/ftp.h
3 // Purpose: documentation for wxFTP class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
11 @headerfile ftp.h wx/protocol/ftp.h
13 wxFTP can be used to establish a connection to an FTP server and perform all the
14 usual operations. Please consult the RFC 959 for more details about the FTP
17 To use a commands which doesn't involve file transfer (i.e. directory oriented
18 commands) you just need to call a corresponding member function or use the
19 generic wxFTP::SendCommand method. However to actually
20 transfer files you just get or give a stream to or from this class and the
21 actual data are read or written using the usual stream methods.
23 Example of using wxFTP for file downloading:
28 // if you don't use these lines anonymous login will be used
30 ftp.SetPassword("password");
32 if ( !ftp.Connect("ftp.wxwindows.org") )
34 wxLogError("Couldn't connect");
39 wxInputStream *in = ftp.GetInputStream("wxWidgets-4.2.0.tar.gz");
42 wxLogError("Coudln't get file");
46 size_t size = in-GetSize();
47 char *data = new char[size];
48 if ( !in-Read(data, size) )
50 wxLogError("Read error");
54 // file data is in the buffer
63 To upload a file you would do (assuming the connection to the server was opened
67 wxOutputStream *out = ftp.GetOutputStream("filename");
70 out-Write(...); // your data
81 class wxFTP
: public wxProtocol
87 #define wxFTP() /* implementation is private */
90 Destructor will close the connection if connected.
92 #define ~wxFTP() /* implementation is private */
95 Aborts the download currently in process, returns @true if ok, @false
101 Change the current FTP working directory.
102 Returns @true if successful.
104 bool ChDir(const wxString
& dir
);
107 Send the specified @e command to the FTP server. @e ret specifies
110 @returns @true if the command has been sent successfully, else @false.
112 bool CheckCommand(const wxString
& command
, char ret
);
115 Returns @true if the given remote file exists, @false otherwise.
117 bool FileExists(const wxString
& filename
);
120 The GetList function is quite low-level. It returns the list of the files in
121 the current directory. The list can be filtered using the @e wildcard string.
122 If @e wildcard is empty (default), it will return all files in directory.
124 The form of the list can change from one peer system to another. For example,
125 for a UNIX peer system, it will look like this:
126 But on Windows system, it will look like this:
127 Return value: @true if the file list was successfully retrieved, @false
132 bool GetDirList(wxArrayString
& files
,
133 const wxString
& wildcard
= "");
136 Returns the file size in bytes or -1 if the file doesn't exist or the size
137 couldn't be determined. Notice that this size can be approximative size only
138 and shouldn't be used for allocating the buffer in which the remote file is
141 int GetFileSize(const wxString
& filename
);
144 This function returns the computer-parsable list of the files in the current
145 directory (optionally only of the files matching the @e wildcard, all files
146 by default). This list always has the same format and contains one full
147 (including the directory path) file name per line.
149 Return value: @true if the file list was successfully retrieved, @false
152 bool GetFilesList(wxArrayString
& files
,
153 const wxString
& wildcard
= "");
156 Creates a new input stream on the specified path. You can use all but the seek
157 functionality of wxStream. Seek isn't available on all streams. For example,
158 HTTP or FTP streams do not deal with it. Other functions like Tell
159 are not available for this sort of stream, at present.
160 You will be notified when the EOF is reached by an error.
162 @returns Returns @NULL if an error occurred (it could be a network failure
163 or the fact that the file doesn't exist).
165 wxInputStream
* GetInputStream(const wxString
& path
);
168 Returns the last command result, i.e. the full server reply for the last
171 const wxString
GetLastResult();
174 Initializes an output stream to the specified @e file. The returned
175 stream has all but the seek functionality of wxStreams. When the user finishes
176 writing data, he has to delete the stream to close it.
178 @returns An initialized write-only stream.
182 wxOutputStream
* GetOutputStream(const wxString
& file
);
185 Create the specified directory in the current FTP working directory.
186 Returns @true if successful.
188 bool MkDir(const wxString
& dir
);
191 Returns the current FTP working directory.
193 #define wxString Pwd() /* implementation is private */
196 Rename the specified @e src element to @e dst. Returns @true if successful.
198 bool Rename(const wxString
& src
, const wxString
& dst
);
201 Remove the specified directory from the current FTP working directory.
202 Returns @true if successful.
204 bool RmDir(const wxString
& dir
);
207 Delete the file specified by @e path. Returns @true if successful.
209 bool RmFile(const wxString
& path
);
212 Send the specified @e command to the FTP server and return the first
213 character of the return code.
215 char SendCommand(const wxString
& command
);
218 Sets the transfer mode to ASCII. It will be used for the next transfer.
223 Sets the transfer mode to binary (IMAGE). It will be used for the next transfer.
228 If @e pasv is @true, passive connection to the FTP server is used. This is
229 the default as it works with practically all firewalls. If the server doesn't
230 support passive move, you may call this function with @false argument to use
233 void SetPassive(bool pasv
);
236 Sets the password to be sent to the FTP server to be allowed to log in.
238 void SetPassword(const wxString
& passwd
);
241 Sets the transfer mode to the specified one. It will be used for the next
244 If this function is never called, binary transfer mode is used by default.
246 bool SetTransferMode(TransferMode mode
);
249 Sets the user name to be sent to the FTP server to be allowed to log in.
251 void SetUser(const wxString
& user
);