00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef PTLIB_FTP_H
00033 #define PTLIB_FTP_H
00034
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038
00039 #include <ptclib/inetprot.h>
00040 #include <ptlib/sockets.h>
00041
00042
00043 class PURL;
00044
00045
00049 class PFTP : public PInternetProtocol
00050 {
00051 PCLASSINFO(PFTP, PInternetProtocol);
00052 public:
00054 enum Commands {
00055 USER, PASS, ACCT, CWD, CDUP, SMNT, QUIT, REIN, PORT, PASV, TYPE,
00056 STRU, MODE, RETR, STOR, STOU, APPE, ALLO, REST, RNFR, RNTO, ABOR,
00057 DELE, RMD, MKD, PWD, LIST, NLST, SITE, SYST, STATcmd, HELP, NOOP,
00058 NumCommands
00059 };
00060
00062 enum RepresentationType {
00063 ASCII,
00064 EBCDIC,
00065 Image
00066 };
00067
00069 enum DataChannelType {
00070 NormalPort,
00071 Passive
00072 };
00073
00075 enum NameTypes {
00076 ShortNames,
00077 DetailedNames
00078 };
00079
00080 enum {
00081 DefaultPort = 21
00082 };
00083
00087 PBoolean SendPORT(
00088 const PIPSocket::Address & addr,
00089 WORD port
00090 );
00091
00092
00093 protected:
00095 PFTP();
00096 };
00097
00098
00102 class PFTPClient : public PFTP
00103 {
00104 PCLASSINFO(PFTPClient, PFTP);
00105 public:
00107 PFTPClient();
00108
00110 ~PFTPClient();
00111
00112
00120 virtual PBoolean Close();
00121
00123
00128 bool OpenHost(
00129 const PString & host,
00130 WORD port = DefaultPort
00131 );
00132
00138 PBoolean LogIn(
00139 const PString & username,
00140 const PString & password
00141 );
00142
00148 PString GetSystemType();
00149
00155 PBoolean SetType(
00156 RepresentationType type
00157 );
00158
00164 PBoolean ChangeDirectory(
00165 const PString & dirPath
00166 );
00167
00173 PString GetCurrentDirectory();
00174
00181 PStringArray GetDirectoryNames(
00182 NameTypes type = ShortNames,
00183 DataChannelType channel = Passive
00184 );
00191 PStringArray GetDirectoryNames(
00192 const PString & path,
00193 NameTypes type = ShortNames,
00194 DataChannelType channel = Passive
00195 );
00196
00202 PBoolean CreateDirectory(
00203 const PString & path
00204 );
00205
00211 PString GetFileStatus(
00212 const PString & path,
00213 DataChannelType channel = Passive
00214 );
00215
00224 PTCPSocket * GetFile(
00225 const PString & filename,
00226 DataChannelType channel = Passive
00227 );
00228
00237 PTCPSocket * PutFile(
00238 const PString & filename,
00239 DataChannelType channel = Passive
00240 );
00241
00250 PTCPSocket * GetURL(
00251 const PURL & url,
00252 RepresentationType type,
00253 DataChannelType channel = Passive
00254 );
00255
00257
00258 protected:
00260 virtual PBoolean OnOpen();
00261
00262 PTCPSocket * NormalClientTransfer(
00263 Commands cmd,
00264 const PString & args
00265 );
00266 PTCPSocket * PassiveClientTransfer(
00267 Commands cmd,
00268 const PString & args
00269 );
00270
00272 WORD remotePort;
00273 };
00274
00275
00279 class PFTPServer : public PFTP
00280 {
00281 PCLASSINFO(PFTPServer, PFTP);
00282 public:
00283 enum { MaxIllegalPasswords = 3 };
00284
00286 PFTPServer();
00287 PFTPServer(
00288 const PString & readyString
00289 );
00290
00292 ~PFTPServer();
00293
00294
00295
00300 virtual PString GetHelloString(const PString & user) const;
00301
00303 virtual PString GetGoodbyeString(const PString & user) const;
00304
00306 virtual PString GetSystemTypeString() const;
00307
00309 PBoolean GetAllowThirdPartyPort() const { return thirdPartyPort; }
00310
00312 void SetAllowThirdPartyPort(PBoolean state) { thirdPartyPort = state; }
00313
00321 PBoolean ProcessCommand();
00322
00330 virtual PBoolean DispatchCommand(
00331 PINDEX code,
00332 const PString & args
00333 );
00334
00335
00342 virtual PBoolean CheckLoginRequired(
00343 PINDEX cmd
00344 );
00345
00354 virtual PBoolean AuthoriseUser(
00355 const PString & user,
00356 const PString & password,
00357 PBoolean & replied
00358 );
00359
00366 virtual PBoolean OnUnknown(
00367 const PCaselessString & command
00368 );
00369
00376 virtual void OnError(
00377 PINDEX errorCode,
00378 PINDEX cmdNum,
00379 const char * msg
00380 );
00381
00383 virtual void OnSyntaxError(
00384 PINDEX cmdNum
00385 );
00386
00388 virtual void OnNotImplemented(
00389 PINDEX cmdNum
00390 );
00391
00393 virtual void OnCommandSuccessful(
00394 PINDEX cmdNum
00395 );
00396
00397
00398
00399
00400 virtual PBoolean OnUSER(const PCaselessString & args);
00401 virtual PBoolean OnPASS(const PCaselessString & args);
00402 virtual PBoolean OnQUIT(const PCaselessString & args);
00403 virtual PBoolean OnPORT(const PCaselessString & args);
00404 virtual PBoolean OnSTRU(const PCaselessString & args);
00405 virtual PBoolean OnMODE(const PCaselessString & args);
00406 virtual PBoolean OnTYPE(const PCaselessString & args);
00407 virtual PBoolean OnNOOP(const PCaselessString & args);
00408 virtual PBoolean OnSYST(const PCaselessString & args);
00409 virtual PBoolean OnSTAT(const PCaselessString & args);
00410
00411
00412
00413 virtual PBoolean OnRETR(const PCaselessString & args);
00414 virtual PBoolean OnSTOR(const PCaselessString & args);
00415 virtual PBoolean OnACCT(const PCaselessString & args);
00416 virtual PBoolean OnAPPE(const PCaselessString & args);
00417 virtual PBoolean OnRNFR(const PCaselessString & args);
00418 virtual PBoolean OnRNTO(const PCaselessString & args);
00419 virtual PBoolean OnDELE(const PCaselessString & args);
00420 virtual PBoolean OnCWD(const PCaselessString & args);
00421 virtual PBoolean OnCDUP(const PCaselessString & args);
00422 virtual PBoolean OnRMD(const PCaselessString & args);
00423 virtual PBoolean OnMKD(const PCaselessString & args);
00424 virtual PBoolean OnPWD(const PCaselessString & args);
00425 virtual PBoolean OnLIST(const PCaselessString & args);
00426 virtual PBoolean OnNLST(const PCaselessString & args);
00427 virtual PBoolean OnPASV(const PCaselessString & args);
00428
00429
00430
00431 virtual PBoolean OnHELP(const PCaselessString & args);
00432 virtual PBoolean OnSITE(const PCaselessString & args);
00433 virtual PBoolean OnABOR(const PCaselessString & args);
00434
00435
00436
00437 virtual PBoolean OnSMNT(const PCaselessString & args);
00438 virtual PBoolean OnREIN(const PCaselessString & args);
00439 virtual PBoolean OnSTOU(const PCaselessString & args);
00440 virtual PBoolean OnALLO(const PCaselessString & args);
00441 virtual PBoolean OnREST(const PCaselessString & args);
00442
00443
00445 void SendToClient(
00446 const PFilePath & filename
00447 );
00448
00449
00450 protected:
00452 PBoolean OnOpen();
00453 void Construct();
00454
00455 PString readyString;
00456 PBoolean thirdPartyPort;
00457
00458 enum {
00459 NotConnected,
00460 NeedUser,
00461 NeedPassword,
00462 Connected,
00463 ClientConnect
00464 } state;
00465
00466 PIPSocket::Address remoteHost;
00467 WORD remotePort;
00468
00469 PTCPSocket * passiveSocket;
00470
00471 char type;
00472 char structure;
00473 char mode;
00474 PString userName;
00475 int illegalPasswordCount;
00476 };
00477
00478
00479 PFACTORY_LOAD(PURL_FtpLoader);
00480
00481
00482 #endif // PTLIB_FTP_H
00483
00484
00485