]>
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 /////////////////////////////////////////////////////////////////////////////
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
80 class wxFTP
: public wxProtocol
89 Destructor will close the connection if connected.
94 Aborts the download currently in process, returns @true if ok, @false
100 Change the current FTP working directory.
101 Returns @true if successful.
103 bool ChDir(const wxString
& dir
);
106 Send the specified @a command to the FTP server. @a ret specifies
109 @returns @true if the command has been sent successfully, else @false.
111 bool CheckCommand(const wxString
& command
, char ret
);
114 Returns @true if the given remote file exists, @false otherwise.
116 bool FileExists(const wxString
& filename
);
119 The GetList function is quite low-level. It returns the list of the files in
120 the current directory. The list can be filtered using the @a wildcard string.
121 If @a wildcard is empty (default), it will return all files in directory.
122 The form of the list can change from one peer system to another. For example,
123 for a UNIX peer system, it will look like this:
125 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.
148 Return value: @true if the file list was successfully retrieved, @false
151 bool GetFilesList(wxArrayString
& files
,
152 const wxString
& wildcard
= "");
155 Creates a new input stream on the specified path. You can use all but the seek
156 functionality of wxStream. Seek isn't available on all streams. For example,
157 HTTP or FTP streams do not deal with it. Other functions like Tell
158 are not available for this sort of stream, at present.
159 You will be notified when the EOF is reached by an error.
161 @returns Returns @NULL if an error occurred (it could be a network failure
162 or the fact that the file doesn't exist).
164 wxInputStream
* GetInputStream(const wxString
& path
);
167 Returns the last command result, i.e. the full server reply for the last
170 const wxString
GetLastResult();
173 Initializes an output stream to the specified @e file. The returned
174 stream has all but the seek functionality of wxStreams. When the user finishes
175 writing data, he has to delete the stream to close it.
177 @returns An initialized write-only stream.
181 wxOutputStream
* GetOutputStream(const wxString
& file
);
184 Create the specified directory in the current FTP working directory.
185 Returns @true if successful.
187 bool MkDir(const wxString
& dir
);
190 Returns the current FTP working directory.
195 Rename the specified @a src element to @e dst. Returns @true if successful.
197 bool Rename(const wxString
& src
, const wxString
& dst
);
200 Remove the specified directory from the current FTP working directory.
201 Returns @true if successful.
203 bool RmDir(const wxString
& dir
);
206 Delete the file specified by @e path. Returns @true if successful.
208 bool RmFile(const wxString
& path
);
211 Send the specified @a command to the FTP server and return the first
212 character of the return code.
214 char SendCommand(const wxString
& command
);
217 Sets the transfer mode to ASCII. It will be used for the next transfer.
222 Sets the transfer mode to binary (IMAGE). It will be used for the next transfer.
227 If @a pasv is @true, passive connection to the FTP server is used. This is
228 the default as it works with practically all firewalls. If the server doesn't
229 support passive move, you may call this function with @false argument to use
232 void SetPassive(bool pasv
);
235 Sets the password to be sent to the FTP server to be allowed to log in.
237 void SetPassword(const wxString
& passwd
);
240 Sets the transfer mode to the specified one. It will be used for the next
242 If this function is never called, binary transfer mode is used by default.
244 bool SetTransferMode(TransferMode mode
);
247 Sets the user name to be sent to the FTP server to be allowed to log in.
249 void SetUser(const wxString
& user
);