PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ftp.h
Go to the documentation of this file.
1 /*
2 * ftp.h
3 *
4 * File Transfer Protocol Server/Client channel classes
5 * As per RFC 959 and RFC 1123
6 *
7 * Portable Windows Library
8 *
9 * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
10 *
11 * The contents of this file are subject to the Mozilla Public License
12 * Version 1.0 (the "License"); you may not use this file except in
13 * compliance with the License. You may obtain a copy of the License at
14 * http://www.mozilla.org/MPL/
15 *
16 * Software distributed under the License is distributed on an "AS IS"
17 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18 * the License for the specific language governing rights and limitations
19 * under the License.
20 *
21 * The Original Code is Portable Windows Library.
22 *
23 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 *
25 * Contributor(s): ______________________________________.
26 *
27 * $Revision: 25574 $
28 * $Author: rjongbloed $
29 * $Date: 2011-04-15 13:32:36 +1000 (Fri, 15 Apr 2011) $
30 */
31
32 #ifndef PTLIB_FTP_H
33 #define PTLIB_FTP_H
34
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38
39 #if P_FTP
40
41 #include <ptclib/inetprot.h>
42 #include <ptlib/sockets.h>
43
44
45 class PURL;
46
47
51 class PFTP : public PInternetProtocol
52 {
53 PCLASSINFO(PFTP, PInternetProtocol);
54 public:
56 enum Commands {
57 USER, PASS, ACCT, CWD, CDUP, SMNT, QUIT, REIN, PORT, PASV, TYPE,
58 STRU, MODE, RETR, STOR, STOU, APPE, ALLO, REST, RNFR, RNTO, ABOR,
59 DELE, RMD, MKD, PWD, LIST, NLST, SITE, SYST, STATcmd, HELP, NOOP,
60 NumCommands
61 };
62
64 enum RepresentationType {
65 ASCII,
66 EBCDIC,
67 Image
68 };
69
71 enum DataChannelType {
72 NormalPort,
73 Passive
74 };
75
77 enum NameTypes {
78 ShortNames,
79 DetailedNames
80 };
81
82 enum {
83 DefaultPort = 21
84 };
85
89 PBoolean SendPORT(
90 const PIPSocket::Address & addr,
91 WORD port
92 );
93
94
95 protected:
97 PFTP();
98 };
99
100
104 class PFTPClient : public PFTP
105 {
106 PCLASSINFO(PFTPClient, PFTP);
107 public:
109 PFTPClient();
110
112 ~PFTPClient();
113
114
122 virtual PBoolean Close();
123
125
130 bool OpenHost(
131 const PString & host,
132 WORD port = DefaultPort
133 );
134
140 PBoolean LogIn(
141 const PString & username,
142 const PString & password
143 );
144
150 PString GetSystemType();
151
157 PBoolean SetType(
158 RepresentationType type
159 );
160
166 PBoolean ChangeDirectory(
167 const PString & dirPath
168 );
169
175 PString GetCurrentDirectory();
176
183 PStringArray GetDirectoryNames(
184 NameTypes type = ShortNames,
185 DataChannelType channel = Passive
186 );
193 PStringArray GetDirectoryNames(
194 const PString & path,
195 NameTypes type = ShortNames,
196 DataChannelType channel = Passive
197 );
198
204 PBoolean CreateDirectory(
205 const PString & path
206 );
207
213 PString GetFileStatus(
214 const PString & path,
215 DataChannelType channel = Passive
216 );
217
226 PTCPSocket * GetFile(
227 const PString & filename,
228 DataChannelType channel = Passive
229 );
230
239 PTCPSocket * PutFile(
240 const PString & filename,
241 DataChannelType channel = Passive
242 );
243
252 PTCPSocket * GetURL(
253 const PURL & url,
254 RepresentationType type,
255 DataChannelType channel = Passive
256 );
257
259
260 protected:
262 virtual PBoolean OnOpen();
263
264 PTCPSocket * NormalClientTransfer(
265 Commands cmd,
266 const PString & args
267 );
268 PTCPSocket * PassiveClientTransfer(
269 Commands cmd,
270 const PString & args
271 );
272
274 WORD remotePort;
275 };
276
277
281 class PFTPServer : public PFTP
282 {
283 PCLASSINFO(PFTPServer, PFTP);
284 public:
285 enum { MaxIllegalPasswords = 3 };
286
288 PFTPServer();
289 PFTPServer(
290 const PString & readyString
291 );
292
294 ~PFTPServer();
295
296
297 // New functions for class
302 virtual PString GetHelloString(const PString & user) const;
303
305 virtual PString GetGoodbyeString(const PString & user) const;
306
308 virtual PString GetSystemTypeString() const;
309
311 PBoolean GetAllowThirdPartyPort() const { return thirdPartyPort; }
312
314 void SetAllowThirdPartyPort(PBoolean state) { thirdPartyPort = state; }
315
323 PBoolean ProcessCommand();
324
332 virtual PBoolean DispatchCommand(
333 PINDEX code,
334 const PString & args
335 );
336
337
344 virtual PBoolean CheckLoginRequired(
345 PINDEX cmd
346 );
347
356 virtual PBoolean AuthoriseUser(
357 const PString & user,
358 const PString & password,
359 PBoolean & replied
360 );
361
368 virtual PBoolean OnUnknown(
369 const PCaselessString & command
370 );
371
378 virtual void OnError(
379 PINDEX errorCode,
380 PINDEX cmdNum,
381 const char * msg
382 );
383
385 virtual void OnSyntaxError(
386 PINDEX cmdNum
387 );
388
390 virtual void OnNotImplemented(
391 PINDEX cmdNum
392 );
393
395 virtual void OnCommandSuccessful(
396 PINDEX cmdNum
397 );
398
399
400 // the following commands must be implemented by all servers
401 // and can be performed without logging in
402 virtual PBoolean OnUSER(const PCaselessString & args);
403 virtual PBoolean OnPASS(const PCaselessString & args); // officially optional, but should be done
404 virtual PBoolean OnQUIT(const PCaselessString & args);
405 virtual PBoolean OnPORT(const PCaselessString & args);
406 virtual PBoolean OnSTRU(const PCaselessString & args);
407 virtual PBoolean OnMODE(const PCaselessString & args);
408 virtual PBoolean OnTYPE(const PCaselessString & args);
409 virtual PBoolean OnNOOP(const PCaselessString & args);
410 virtual PBoolean OnSYST(const PCaselessString & args);
411 virtual PBoolean OnSTAT(const PCaselessString & args);
412
413 // the following commands must be implemented by all servers
414 // and cannot be performed without logging in
415 virtual PBoolean OnRETR(const PCaselessString & args);
416 virtual PBoolean OnSTOR(const PCaselessString & args);
417 virtual PBoolean OnACCT(const PCaselessString & args);
418 virtual PBoolean OnAPPE(const PCaselessString & args);
419 virtual PBoolean OnRNFR(const PCaselessString & args);
420 virtual PBoolean OnRNTO(const PCaselessString & args);
421 virtual PBoolean OnDELE(const PCaselessString & args);
422 virtual PBoolean OnCWD(const PCaselessString & args);
423 virtual PBoolean OnCDUP(const PCaselessString & args);
424 virtual PBoolean OnRMD(const PCaselessString & args);
425 virtual PBoolean OnMKD(const PCaselessString & args);
426 virtual PBoolean OnPWD(const PCaselessString & args);
427 virtual PBoolean OnLIST(const PCaselessString & args);
428 virtual PBoolean OnNLST(const PCaselessString & args);
429 virtual PBoolean OnPASV(const PCaselessString & args);
430
431 // the following commands are optional and can be performed without
432 // logging in
433 virtual PBoolean OnHELP(const PCaselessString & args);
434 virtual PBoolean OnSITE(const PCaselessString & args);
435 virtual PBoolean OnABOR(const PCaselessString & args);
436
437 // the following commands are optional and cannot be performed
438 // without logging in
439 virtual PBoolean OnSMNT(const PCaselessString & args);
440 virtual PBoolean OnREIN(const PCaselessString & args);
441 virtual PBoolean OnSTOU(const PCaselessString & args);
442 virtual PBoolean OnALLO(const PCaselessString & args);
443 virtual PBoolean OnREST(const PCaselessString & args);
444
445
447 void SendToClient(
448 const PFilePath & filename
449 );
450
451
452 protected:
454 PBoolean OnOpen();
455 void Construct();
456
457 PString readyString;
458 PBoolean thirdPartyPort;
459
460 enum {
461 NotConnected,
462 NeedUser,
463 NeedPassword,
464 Connected,
465 ClientConnect
466 } state;
467
468 PIPSocket::Address remoteHost;
469 WORD remotePort;
470
471 PTCPSocket * passiveSocket;
472
473 char type;
474 char structure;
475 char mode;
476 PString userName;
477 int illegalPasswordCount;
478 };
479
480
481 #endif // P_FTP
482
483 #endif // PTLIB_FTP_H
484
485
486 // End of File ///////////////////////////////////////////////////////////////