PTLib  Version 2.10.11
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: 25012 $
28  * $Author: rjongbloed $
29  * $Date: 2011-01-06 01:01:23 -0600 (Thu, 06 Jan 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 #include <ptclib/inetprot.h>
40 #include <ptlib/sockets.h>
41 
42 
43 class PURL;
44 
45 
49 class PFTP : public PInternetProtocol
50 {
51  PCLASSINFO(PFTP, PInternetProtocol);
52  public:
54  enum Commands {
59  };
60 
66  };
67 
72  };
73 
75  enum NameTypes {
78  };
79 
80  enum {
82  };
83 
88  const PIPSocket::Address & addr,
89  WORD port
90  );
91 
92 
93  protected:
95  PFTP();
96 };
97 
98 
102 class PFTPClient : public PFTP
103 {
105  public:
107  PFTPClient();
108 
110  ~PFTPClient();
111 
112 
120  virtual PBoolean Close();
121 
123 
128  bool OpenHost(
129  const PString & host,
130  WORD port = DefaultPort
131  );
132 
138  PBoolean LogIn(
139  const PString & username,
140  const PString & password
141  );
142 
148  PString GetSystemType();
149 
155  PBoolean SetType(
156  RepresentationType type
157  );
158 
164  PBoolean ChangeDirectory(
165  const PString & dirPath
166  );
167 
173  PString GetCurrentDirectory();
174 
181  PStringArray GetDirectoryNames(
182  NameTypes type = ShortNames,
183  DataChannelType channel = Passive
184  );
191  PStringArray GetDirectoryNames(
192  const PString & path,
193  NameTypes type = ShortNames,
194  DataChannelType channel = Passive
195  );
196 
202  PBoolean CreateDirectory(
203  const PString & path
204  );
205 
211  PString GetFileStatus(
212  const PString & path,
213  DataChannelType channel = Passive
214  );
215 
224  PTCPSocket * GetFile(
225  const PString & filename,
226  DataChannelType channel = Passive
227  );
228 
237  PTCPSocket * PutFile(
238  const PString & filename,
239  DataChannelType channel = Passive
240  );
241 
250  PTCPSocket * GetURL(
251  const PURL & url,
252  RepresentationType type,
253  DataChannelType channel = Passive
254  );
255 
257 
258  protected:
260  virtual PBoolean OnOpen();
261 
262  PTCPSocket * NormalClientTransfer(
263  Commands cmd,
264  const PString & args
265  );
266  PTCPSocket * PassiveClientTransfer(
267  Commands cmd,
268  const PString & args
269  );
270 
273 };
274 
275 
279 class PFTPServer : public PFTP
280 {
282  public:
283  enum { MaxIllegalPasswords = 3 };
284 
286  PFTPServer();
287  PFTPServer(
288  const PString & readyString
289  );
290 
292  ~PFTPServer();
293 
294 
295  // New functions for class
300  virtual PString GetHelloString(const PString & user) const;
301 
303  virtual PString GetGoodbyeString(const PString & user) const;
304 
306  virtual PString GetSystemTypeString() const;
307 
309  PBoolean GetAllowThirdPartyPort() const { return thirdPartyPort; }
310 
312  void SetAllowThirdPartyPort(PBoolean state) { thirdPartyPort = state; }
313 
321  PBoolean ProcessCommand();
322 
330  virtual PBoolean DispatchCommand(
331  PINDEX code,
332  const PString & args
333  );
334 
335 
342  virtual PBoolean CheckLoginRequired(
343  PINDEX cmd
344  );
345 
354  virtual PBoolean AuthoriseUser(
355  const PString & user,
356  const PString & password,
357  PBoolean & replied
358  );
359 
366  virtual PBoolean OnUnknown(
367  const PCaselessString & command
368  );
369 
376  virtual void OnError(
377  PINDEX errorCode,
378  PINDEX cmdNum,
379  const char * msg
380  );
381 
383  virtual void OnSyntaxError(
384  PINDEX cmdNum
385  );
386 
388  virtual void OnNotImplemented(
389  PINDEX cmdNum
390  );
391 
393  virtual void OnCommandSuccessful(
394  PINDEX cmdNum
395  );
396 
397 
398  // the following commands must be implemented by all servers
399  // and can be performed without logging in
400  virtual PBoolean OnUSER(const PCaselessString & args);
401  virtual PBoolean OnPASS(const PCaselessString & args); // officially optional, but should be done
402  virtual PBoolean OnQUIT(const PCaselessString & args);
403  virtual PBoolean OnPORT(const PCaselessString & args);
404  virtual PBoolean OnSTRU(const PCaselessString & args);
405  virtual PBoolean OnMODE(const PCaselessString & args);
406  virtual PBoolean OnTYPE(const PCaselessString & args);
407  virtual PBoolean OnNOOP(const PCaselessString & args);
408  virtual PBoolean OnSYST(const PCaselessString & args);
409  virtual PBoolean OnSTAT(const PCaselessString & args);
410 
411  // the following commands must be implemented by all servers
412  // and cannot be performed without logging in
413  virtual PBoolean OnRETR(const PCaselessString & args);
414  virtual PBoolean OnSTOR(const PCaselessString & args);
415  virtual PBoolean OnACCT(const PCaselessString & args);
416  virtual PBoolean OnAPPE(const PCaselessString & args);
417  virtual PBoolean OnRNFR(const PCaselessString & args);
418  virtual PBoolean OnRNTO(const PCaselessString & args);
419  virtual PBoolean OnDELE(const PCaselessString & args);
420  virtual PBoolean OnCWD(const PCaselessString & args);
421  virtual PBoolean OnCDUP(const PCaselessString & args);
422  virtual PBoolean OnRMD(const PCaselessString & args);
423  virtual PBoolean OnMKD(const PCaselessString & args);
424  virtual PBoolean OnPWD(const PCaselessString & args);
425  virtual PBoolean OnLIST(const PCaselessString & args);
426  virtual PBoolean OnNLST(const PCaselessString & args);
427  virtual PBoolean OnPASV(const PCaselessString & args);
428 
429  // the following commands are optional and can be performed without
430  // logging in
431  virtual PBoolean OnHELP(const PCaselessString & args);
432  virtual PBoolean OnSITE(const PCaselessString & args);
433  virtual PBoolean OnABOR(const PCaselessString & args);
434 
435  // the following commands are optional and cannot be performed
436  // without logging in
437  virtual PBoolean OnSMNT(const PCaselessString & args);
438  virtual PBoolean OnREIN(const PCaselessString & args);
439  virtual PBoolean OnSTOU(const PCaselessString & args);
440  virtual PBoolean OnALLO(const PCaselessString & args);
441  virtual PBoolean OnREST(const PCaselessString & args);
442 
443 
445  void SendToClient(
446  const PFilePath & filename
447  );
448 
449 
450  protected:
452  PBoolean OnOpen();
453  void Construct();
454 
457 
458  enum {
463  ClientConnect
464  } state;
465 
468 
470 
471  char type;
472  char structure;
473  char mode;
476 };
477 
478 
479 PFACTORY_LOAD(PURL_FtpLoader);
480 
481 
482 #endif // PTLIB_FTP_H
483 
484 
485 // End of File ///////////////////////////////////////////////////////////////
Definition: ftp.h:57
void SetAllowThirdPartyPort(PBoolean state)
Set the thirdPartyPort flag.
Definition: ftp.h:312
Definition: ftp.h:57
Definition: ftp.h:55
int illegalPasswordCount
Definition: ftp.h:475
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
WORD remotePort
Port number on remote system.
Definition: ftp.h:272
Definition: ftp.h:70
Definition: ftp.h:56
Definition: ftp.h:57
Definition: ftp.h:76
Definition: ftp.h:63
PTCPSocket * passiveSocket
Definition: ftp.h:469
File Transfer Protocol client channel class.
Definition: ftp.h:102
Definition: ftp.h:56
Definition: ftp.h:460
PFTP()
Construct an ineternal File Transfer Protocol channel.
PString userName
Definition: ftp.h:474
This class describes a full description for a file on the particular platform.
Definition: filepath.h:65
Definition: ftp.h:57
Definition: ftp.h:56
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
char mode
Definition: ftp.h:473
Definition: ftp.h:57
PFACTORY_LOAD(PURL_FtpLoader)
char type
Definition: ftp.h:471
NameTypes
Listing types.
Definition: ftp.h:75
WORD remotePort
Definition: ftp.h:467
This is an array collection class of PString objects.
Definition: pstring.h:2024
File Transfer Protocol server channel class.
Definition: ftp.h:279
Definition: ftp.h:81
File Transfer Protocol base class.
Definition: ftp.h:49
Definition: ftp.h:55
A TCP/IP socket for process/application layer high level protocols.
Definition: inetprot.h:62
Definition: ftp.h:57
Definition: ftp.h:459
BOOL PBoolean
Definition: object.h:102
Definition: ftp.h:55
char structure
Definition: ftp.h:472
Definition: ftp.h:462
Commands
FTP commands.
Definition: ftp.h:54
Definition: ftp.h:55
PBoolean thirdPartyPort
Definition: ftp.h:456
virtual PBoolean Close()
Close the channel.
Definition: ftp.h:55
Definition: ftp.h:57
PIPSocket::Address remoteHost
Definition: ftp.h:466
Definition: ftp.h:56
Definition: ftp.h:77
Definition: ftp.h:55
RepresentationType
Types for file transfer.
Definition: ftp.h:62
Definition: ftp.h:57
The character string class.
Definition: pstring.h:108
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:44
Definition: ftp.h:55
virtual PBoolean OnOpen()
This callback is executed when the Open() function is called with open channels.
PBoolean SendPORT(const PIPSocket::Address &addr, WORD port)
Send the PORT command for a transfer.
Definition: ftp.h:56
Definition: ftp.h:57
Definition: ftp.h:56
A class describing an IP address.
Definition: ipsock.h:75
Definition: ftp.h:461
Definition: ftp.h:56
Definition: ftp.h:57
Definition: ftp.h:56
Definition: ftp.h:65
PBoolean GetAllowThirdPartyPort() const
return the thirdPartyPort flag, allowing 3 host put and get.
Definition: ftp.h:309
Definition: ftp.h:56
Definition: ftp.h:58
PString readyString
Definition: ftp.h:455
Definition: ftp.h:55
DataChannelType
File transfer mode on data channel.
Definition: ftp.h:69
Definition: ftp.h:71
Definition: ftp.h:55
Definition: ftp.h:57
This class describes a Universal Resource Locator.
Definition: url.h:54
Definition: ftp.h:64
Definition: ftp.h:55
Definition: ftp.h:56
Definition: ftp.h:56
Definition: ftp.h:55