ftp.h
Go to the documentation of this file.
/*
* ftp.h
*
* File Transfer Protocol Server/Client channel classes
* As per RFC 959 and RFC 1123
*
* Portable Windows Library
*
* Copyright (c) 1993-2002 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 25012 $
* $Author: rjongbloed $
* $Date: 2011-01-06 01:01:23 -0600 (Thu, 06 Jan 2011) $
*/
#ifndef PTLIB_FTP_H
#define PTLIB_FTP_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptclib/inetprot.h>
#include <ptlib/sockets.h>
class PURL;
class PFTP : public PInternetProtocol
{
PCLASSINFO(PFTP, PInternetProtocol);
public:
enum Commands {
USER, PASS, ACCT, CWD, CDUP, SMNT, QUIT, REIN, PORT, PASV, TYPE,
STRU, MODE, RETR, STOR, STOU, APPE, ALLO, REST, RNFR, RNTO, ABOR,
DELE, RMD, MKD, PWD, LIST, NLST, SITE, SYST, STATcmd, HELP, NOOP,
NumCommands
};
enum RepresentationType {
ASCII,
EBCDIC,
Image
};
enum DataChannelType {
NormalPort,
Passive
};
enum NameTypes {
ShortNames,
DetailedNames
};
enum {
DefaultPort = 21
};
PBoolean SendPORT(
const PIPSocket::Address & addr,
WORD port
);
protected:
PFTP();
};
class PFTPClient : public PFTP
{
PCLASSINFO(PFTPClient, PFTP);
public:
PFTPClient();
~PFTPClient();
virtual PBoolean Close();
bool OpenHost(
const PString & host,
WORD port = DefaultPort
);
PBoolean LogIn(
const PString & username,
const PString & password
);
PString GetSystemType();
PBoolean SetType(
RepresentationType type
);
PBoolean ChangeDirectory(
const PString & dirPath
);
PString GetCurrentDirectory();
PStringArray GetDirectoryNames(
NameTypes type = ShortNames,
DataChannelType channel = Passive
);
PStringArray GetDirectoryNames(
const PString & path,
NameTypes type = ShortNames,
DataChannelType channel = Passive
);
PBoolean CreateDirectory(
const PString & path
);
PString GetFileStatus(
const PString & path,
DataChannelType channel = Passive
);
PTCPSocket * GetFile(
const PString & filename,
DataChannelType channel = Passive
);
PTCPSocket * PutFile(
const PString & filename,
DataChannelType channel = Passive
);
PTCPSocket * GetURL(
const PURL & url,
RepresentationType type,
DataChannelType channel = Passive
);
protected:
virtual PBoolean OnOpen();
PTCPSocket * NormalClientTransfer(
Commands cmd,
const PString & args
);
PTCPSocket * PassiveClientTransfer(
Commands cmd,
const PString & args
);
WORD remotePort;
};
class PFTPServer : public PFTP
{
PCLASSINFO(PFTPServer, PFTP);
public:
enum { MaxIllegalPasswords = 3 };
PFTPServer();
PFTPServer(
const PString & readyString
);
~PFTPServer();
// New functions for class
virtual PString GetHelloString(const PString & user) const;
virtual PString GetGoodbyeString(const PString & user) const;
virtual PString GetSystemTypeString() const;
PBoolean GetAllowThirdPartyPort() const { return thirdPartyPort; }
void SetAllowThirdPartyPort(PBoolean state) { thirdPartyPort = state; }
PBoolean ProcessCommand();
virtual PBoolean DispatchCommand(
PINDEX code,
const PString & args
);
virtual PBoolean CheckLoginRequired(
PINDEX cmd
);
virtual PBoolean AuthoriseUser(
const PString & user,
const PString & password,
PBoolean & replied
);
virtual PBoolean OnUnknown(
const PCaselessString & command
);
virtual void OnError(
PINDEX errorCode,
PINDEX cmdNum,
const char * msg
);
virtual void OnSyntaxError(
PINDEX cmdNum
);
virtual void OnNotImplemented(
PINDEX cmdNum
);
virtual void OnCommandSuccessful(
PINDEX cmdNum
);
// the following commands must be implemented by all servers
// and can be performed without logging in
virtual PBoolean OnUSER(const PCaselessString & args);
virtual PBoolean OnPASS(const PCaselessString & args); // officially optional, but should be done
virtual PBoolean OnQUIT(const PCaselessString & args);
virtual PBoolean OnPORT(const PCaselessString & args);
virtual PBoolean OnSTRU(const PCaselessString & args);
virtual PBoolean OnMODE(const PCaselessString & args);
virtual PBoolean OnTYPE(const PCaselessString & args);
virtual PBoolean OnNOOP(const PCaselessString & args);
virtual PBoolean OnSYST(const PCaselessString & args);
virtual PBoolean OnSTAT(const PCaselessString & args);
// the following commands must be implemented by all servers
// and cannot be performed without logging in
virtual PBoolean OnRETR(const PCaselessString & args);
virtual PBoolean OnSTOR(const PCaselessString & args);
virtual PBoolean OnACCT(const PCaselessString & args);
virtual PBoolean OnAPPE(const PCaselessString & args);
virtual PBoolean OnRNFR(const PCaselessString & args);
virtual PBoolean OnRNTO(const PCaselessString & args);
virtual PBoolean OnDELE(const PCaselessString & args);
virtual PBoolean OnCWD(const PCaselessString & args);
virtual PBoolean OnCDUP(const PCaselessString & args);
virtual PBoolean OnRMD(const PCaselessString & args);
virtual PBoolean OnMKD(const PCaselessString & args);
virtual PBoolean OnPWD(const PCaselessString & args);
virtual PBoolean OnLIST(const PCaselessString & args);
virtual PBoolean OnNLST(const PCaselessString & args);
virtual PBoolean OnPASV(const PCaselessString & args);
// the following commands are optional and can be performed without
// logging in
virtual PBoolean OnHELP(const PCaselessString & args);
virtual PBoolean OnSITE(const PCaselessString & args);
virtual PBoolean OnABOR(const PCaselessString & args);
// the following commands are optional and cannot be performed
// without logging in
virtual PBoolean OnSMNT(const PCaselessString & args);
virtual PBoolean OnREIN(const PCaselessString & args);
virtual PBoolean OnSTOU(const PCaselessString & args);
virtual PBoolean OnALLO(const PCaselessString & args);
virtual PBoolean OnREST(const PCaselessString & args);
void SendToClient(
const PFilePath & filename
);
protected:
PBoolean OnOpen();
void Construct();
PString readyString;
PBoolean thirdPartyPort;
enum {
NotConnected,
NeedUser,
NeedPassword,
Connected,
ClientConnect
} state;
PIPSocket::Address remoteHost;
WORD remotePort;
PTCPSocket * passiveSocket;
char type;
char structure;
char mode;
PString userName;
int illegalPasswordCount;
};
PFACTORY_LOAD(PURL_FtpLoader);
#endif // PTLIB_FTP_H
// End of File ///////////////////////////////////////////////////////////////
PFTP::NOOP
Definition: ftp.h:57
PFTPServer::SetAllowThirdPartyPort
void SetAllowThirdPartyPort(PBoolean state)
Set the thirdPartyPort flag.
Definition: ftp.h:312
inetprot.h
PFTP::NLST
Definition: ftp.h:57
PFTP::PORT
Definition: ftp.h:55
PFTPServer::illegalPasswordCount
int illegalPasswordCount
Definition: ftp.h:475
PCLASSINFO
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
PFTPClient::remotePort
WORD remotePort
Port number on remote system.
Definition: ftp.h:272
PFTP::NormalPort
Definition: ftp.h:70
PFTP::REST
Definition: ftp.h:56
PFTP::MKD
Definition: ftp.h:57
PFTP::ShortNames
Definition: ftp.h:76
PFTP::ASCII
Definition: ftp.h:63
PFTPServer::passiveSocket
PTCPSocket * passiveSocket
Definition: ftp.h:469
PFTPClient
File Transfer Protocol client channel class.
Definition: ftp.h:102
PFTP::STRU
Definition: ftp.h:56
PFTPServer::NeedUser
Definition: ftp.h:460
PFTP::PFTP
PFTP()
Construct an ineternal File Transfer Protocol channel.
PFTPServer::userName
PString userName
Definition: ftp.h:474
PFilePath
This class describes a full description for a file on the particular platform.
Definition: filepath.h:65
PFTP::SYST
Definition: ftp.h:57
PFTP::APPE
Definition: ftp.h:56
PCaselessString
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
PFTPServer::mode
char mode
Definition: ftp.h:473
PFTP::STATcmd
Definition: ftp.h:57
PFACTORY_LOAD
PFACTORY_LOAD(PURL_FtpLoader)
PFTPServer::type
char type
Definition: ftp.h:471
PFTP::NameTypes
NameTypes
Listing types.
Definition: ftp.h:75
PFTPServer::remotePort
WORD remotePort
Definition: ftp.h:467
PStringArray
This is an array collection class of PString objects.
Definition: pstring.h:2024
PFTPServer
File Transfer Protocol server channel class.
Definition: ftp.h:279
PFTP::DefaultPort
Definition: ftp.h:81
PFTP
File Transfer Protocol base class.
Definition: ftp.h:49
PFTP::REIN
Definition: ftp.h:55
PInternetProtocol
A TCP/IP socket for process/application layer high level protocols.
Definition: inetprot.h:62
PFTP::SITE
Definition: ftp.h:57
PFTPServer::NotConnected
Definition: ftp.h:459
PBoolean
BOOL PBoolean
Definition: object.h:102
PFTP::PASV
Definition: ftp.h:55
PFTPServer::structure
char structure
Definition: ftp.h:472
PFTPServer::Connected
Definition: ftp.h:462
PFTP::Commands
Commands
FTP commands.
Definition: ftp.h:54
PFTP::ACCT
Definition: ftp.h:55
PFTPServer::thirdPartyPort
PBoolean thirdPartyPort
Definition: ftp.h:456
PIndirectChannel::Close
virtual PBoolean Close()
Close the channel.
PFTP::CWD
Definition: ftp.h:55
PFTP::HELP
Definition: ftp.h:57
PFTPServer::remoteHost
PIPSocket::Address remoteHost
Definition: ftp.h:466
PFTP::ABOR
Definition: ftp.h:56
PFTP::DetailedNames
Definition: ftp.h:77
PFTP::TYPE
Definition: ftp.h:55
PFTP::RepresentationType
RepresentationType
Types for file transfer.
Definition: ftp.h:62
PFTP::DELE
Definition: ftp.h:57
PString
The character string class.
Definition: pstring.h:108
PTCPSocket
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:44
PFTP::USER
Definition: ftp.h:55
PFTPServer::GetAllowThirdPartyPort
PBoolean GetAllowThirdPartyPort() const
return the thirdPartyPort flag, allowing 3 host put and get.
Definition: ftp.h:309
PIndirectChannel::OnOpen
virtual PBoolean OnOpen()
This callback is executed when the Open() function is called with open channels.
PFTP::SendPORT
PBoolean SendPORT(const PIPSocket::Address &addr, WORD port)
Send the PORT command for a transfer.
PFTP::STOR
Definition: ftp.h:56
PFTP::RMD
Definition: ftp.h:57
PFTP::RETR
Definition: ftp.h:56
PIPSocket::Address
A class describing an IP address.
Definition: ipsock.h:75
PFTPServer::NeedPassword
Definition: ftp.h:461
PFTP::MODE
Definition: ftp.h:56
PFTP::PWD
Definition: ftp.h:57
PFTP::RNFR
Definition: ftp.h:56
PFTP::Image
Definition: ftp.h:65
PFTP::ALLO
Definition: ftp.h:56
PFTP::NumCommands
Definition: ftp.h:58
sockets.h
PFTPServer::readyString
PString readyString
Definition: ftp.h:455
PFTP::QUIT
Definition: ftp.h:55
PFTP::DataChannelType
DataChannelType
File transfer mode on data channel.
Definition: ftp.h:69
PFTP::Passive
Definition: ftp.h:71
PFTP::PASS
Definition: ftp.h:55
PFTP::LIST
Definition: ftp.h:57
PURL
This class describes a Universal Resource Locator.
Definition: url.h:54
PFTP::EBCDIC
Definition: ftp.h:64
PFTP::CDUP
Definition: ftp.h:55
PFTP::STOU
Definition: ftp.h:56
PFTP::RNTO
Definition: ftp.h:56
PFTP::SMNT
Definition: ftp.h:55