📄 ftp.h
字号:
client and in passive mode the client connects to the server.
@return
Socket to read data from, or NULL if an error occurred.
*/
PTCPSocket * GetFile(
const PString & filename, ///< Name of file to get
DataChannelType channel = NormalPort ///< Data channel type.
);
/**Begin storing a file to the remote FTP server. The second parameter
indicates that the transfer is on a normal or passive data channel.
In short, a normal transfer the server connects to the client and in
passive mode the client connects to the server.
@return
Socket to write data to, or NULL if an error occurred.
*/
PTCPSocket * PutFile(
const PString & filename, ///< Name of file to get
DataChannelType channel = NormalPort ///< Data channel type.
);
//@}
protected:
/// Call back to verify open succeeded in an PInternetProtocol class
virtual BOOL OnOpen();
PTCPSocket * NormalClientTransfer(
Commands cmd,
const PString & args
);
PTCPSocket * PassiveClientTransfer(
Commands cmd,
const PString & args
);
/// Port number on remote system
WORD remotePort;
};
/**
File Transfer Protocol server channel class.
*/
class PFTPServer : public PFTP
{
PCLASSINFO(PFTPServer, PFTP);
public:
enum { MaxIllegalPasswords = 3 };
/// declare a server socket
PFTPServer();
PFTPServer(
const PString & readyString ///< Sign on string on connection ready.
);
/// Delete the server, cleaning up passive sockets.
~PFTPServer();
// New functions for class
/**
Get the string printed when a user logs in default value is a string
giving the user name
*/
virtual PString GetHelloString(const PString & user) const;
/// return the string printed just before exiting
virtual PString GetGoodbyeString(const PString & user) const;
/// return the string to be returned by the SYST command
virtual PString GetSystemTypeString() const;
/// return the thirdPartyPort flag, allowing 3 host put and get.
BOOL GetAllowThirdPartyPort() const { return thirdPartyPort; }
/// Set the thirdPartyPort flag.
void SetAllowThirdPartyPort(BOOL state) { thirdPartyPort = state; }
/** Process commands, dispatching to the appropriate virtual function. This
is used when the socket is acting as a server.
@return
TRUE if more processing may be done, FALSE if the QUIT command was
received or the #OnUnknown()# function returns FALSE.
*/
BOOL ProcessCommand();
/** Dispatching to the appropriate virtual function. This is used when the
socket is acting as a server.
@return
TRUE if more processing may be done, FALSE if the QUIT command was
received or the #OnUnknown()# function returns FALSE.
*/
virtual BOOL DispatchCommand(
PINDEX code, ///< Parsed command code.
const PString & args ///< Arguments to command.
);
/** Check to see if the command requires the server to be logged in before
it may be processed.
@return
TRUE if the command required the user to be logged in.
*/
virtual BOOL CheckLoginRequired(
PINDEX cmd ///< Command to check if log in required.
);
/** Validate the user name and password for access. After three invalid
attempts, the socket will close and FALSE is returned.
Default implementation returns TRUE for all strings.
@return
TRUE if user can access, otherwise FALSE
*/
virtual BOOL AuthoriseUser(
const PString & user, ///< User name to authorise.
const PString & password, ///< Password supplied for the user.
BOOL & replied ///< Indication that a reply was sent to client.
);
/** Handle an unknown command.
@return
TRUE if more processing may be done, FALSE if the
#ProcessCommand()# function is to return FALSE.
*/
virtual BOOL OnUnknown(
const PCaselessString & command ///< Complete command line received.
);
/** Handle an error in command.
@return
TRUE if more processing may be done, FALSE if the
#ProcessCommand()# function is to return FALSE.
*/
virtual void OnError(
PINDEX errorCode, ///< Error code to use
PINDEX cmdNum, ///< Command that had the error.
const char * msg ///< Error message.
);
/// Called for syntax errors in commands.
virtual void OnSyntaxError(
PINDEX cmdNum ///< Command that had the syntax error.
);
/// Called for unimplemented commands.
virtual void OnNotImplemented(
PINDEX cmdNum ///< Command that was not implemented.
);
/// Called for successful commands.
virtual void OnCommandSuccessful(
PINDEX cmdNum ///< Command that had was successful.
);
// the following commands must be implemented by all servers
// and can be performed without logging in
virtual BOOL OnUSER(const PCaselessString & args);
virtual BOOL OnPASS(const PCaselessString & args); // officially optional, but should be done
virtual BOOL OnQUIT(const PCaselessString & args);
virtual BOOL OnPORT(const PCaselessString & args);
virtual BOOL OnSTRU(const PCaselessString & args);
virtual BOOL OnMODE(const PCaselessString & args);
virtual BOOL OnTYPE(const PCaselessString & args);
virtual BOOL OnNOOP(const PCaselessString & args);
virtual BOOL OnSYST(const PCaselessString & args);
virtual BOOL OnSTAT(const PCaselessString & args);
// the following commands must be implemented by all servers
// and cannot be performed without logging in
virtual BOOL OnRETR(const PCaselessString & args);
virtual BOOL OnSTOR(const PCaselessString & args);
virtual BOOL OnACCT(const PCaselessString & args);
virtual BOOL OnAPPE(const PCaselessString & args);
virtual BOOL OnRNFR(const PCaselessString & args);
virtual BOOL OnRNTO(const PCaselessString & args);
virtual BOOL OnDELE(const PCaselessString & args);
virtual BOOL OnCWD(const PCaselessString & args);
virtual BOOL OnCDUP(const PCaselessString & args);
virtual BOOL OnRMD(const PCaselessString & args);
virtual BOOL OnMKD(const PCaselessString & args);
virtual BOOL OnPWD(const PCaselessString & args);
virtual BOOL OnLIST(const PCaselessString & args);
virtual BOOL OnNLST(const PCaselessString & args);
virtual BOOL OnPASV(const PCaselessString & args);
// the following commands are optional and can be performed without
// logging in
virtual BOOL OnHELP(const PCaselessString & args);
virtual BOOL OnSITE(const PCaselessString & args);
virtual BOOL OnABOR(const PCaselessString & args);
// the following commands are optional and cannot be performed
// without logging in
virtual BOOL OnSMNT(const PCaselessString & args);
virtual BOOL OnREIN(const PCaselessString & args);
virtual BOOL OnSTOU(const PCaselessString & args);
virtual BOOL OnALLO(const PCaselessString & args);
virtual BOOL OnREST(const PCaselessString & args);
/// Send the specified file to the client.
void SendToClient(
const PFilePath & filename ///< File name to send.
);
protected:
/// Call back to verify open succeeded in an PInternetProtocol class
BOOL OnOpen();
void Construct();
PString readyString;
BOOL 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;
};
#endif
// End of File ///////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -