X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7c4728f63395c3641aa62f2b549ee693eb8be978..1f0acb435592470b421b80df854fbbb08cd2853f:/include/wx/protocol/ftp.h diff --git a/include/wx/protocol/ftp.h b/include/wx/protocol/ftp.h index 5356267702..894c52420c 100644 --- a/include/wx/protocol/ftp.h +++ b/include/wx/protocol/ftp.h @@ -1,9 +1,9 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: ftp.h +// Name: wx/protocol/ftp.h // Purpose: FTP protocol // Author: Vadim Zeitlin -// Modified by: Mark Johnson, wxWindows@mj10777.de -// 20000917 : RmDir, GetLastResult, GetList +// Modified by: Mark Johnson, wxWindows@mj10777.de +// 20000917 : RmDir, GetLastResult, GetList // Created: 07/07/1997 // RCS-ID: $Id$ // Copyright: (c) 1997, 1998 Guilhem Lavaux @@ -13,10 +13,6 @@ #ifndef __WX_FTP_H__ #define __WX_FTP_H__ -#if defined(__GNUG__) && !defined(__APPLE__) - #pragma interface "ftp.h" -#endif - #include "wx/defs.h" #if wxUSE_PROTOCOL_FTP @@ -39,11 +35,9 @@ public: virtual ~wxFTP(); // Connecting and disconnecting - void SetUser(const wxString& user) { m_user = user; } - void SetPassword(const wxString& passwd) { m_passwd = passwd; } - - bool Connect(wxSockAddress& addr, bool wait = TRUE); - bool Connect(const wxString& host); + virtual bool Connect(const wxSockAddress& addr, bool wait = true); + virtual bool Connect(const wxString& host) { return Connect(host, 0); } + virtual bool Connect(const wxString& host, unsigned short port); // disconnect virtual bool Close(); @@ -51,17 +45,18 @@ public: // Parameters set up // set transfer mode now + void SetPassive(bool pasv) { m_bPassive = pasv; } bool SetBinary() { return SetTransferMode(BINARY); } bool SetAscii() { return SetTransferMode(ASCII); } bool SetTransferMode(TransferMode mode); // Generic FTP interface - // the error code - virtual wxProtocolError GetError() { return m_lastError; } + // FTP doesn't know the MIME type of the last downloaded/uploaded file + virtual wxString GetContentType() const { return wxEmptyString; } // the last FTP server reply - const wxString& GetLastResult() { return m_lastResult; } + const wxString& GetLastResult() const { return m_lastResult; } // send any FTP command (should be full FTP command line but without // trailing "\r\n") and return its return code @@ -70,6 +65,7 @@ public: // check that the command returned the given code bool CheckCommand(const wxString& command, char expectedReturn) { + // SendCommand() does updates m_lastError return SendCommand(command) == expectedReturn; } @@ -83,9 +79,9 @@ public: // Get the size of a file in the current dir. // this function tries its best to deliver the size in bytes using BINARY - // (the SIZE command reports different sizes depending on whether + // (the SIZE command reports different sizes depending on whether // type is set to ASCII or BINARY) - // returns -1 if file is non-existant or size could not be found + // returns -1 if file is non-existent or size could not be found int GetFileSize(const wxString& fileName); // Check to see if a file exists in the current dir @@ -104,7 +100,7 @@ public: bool GetFilesList(wxArrayString& files, const wxString& wildcard = wxEmptyString) { - return GetList(files, wildcard, FALSE); + return GetList(files, wildcard, false); } // get a directory list in server dependent format - this can be shown @@ -112,46 +108,58 @@ public: bool GetDirList(wxArrayString& files, const wxString& wildcard = wxEmptyString) { - return GetList(files, wildcard, TRUE); + return GetList(files, wildcard, true); } // equivalent to either GetFilesList() (default) or GetDirList() bool GetList(wxArrayString& files, const wxString& wildcard = wxEmptyString, - bool details = FALSE); - -#if WXWIN_COMPATIBILITY_2 - // deprecated - wxList *GetList(const wxString& wildcard, bool details = FALSE); -#endif // WXWIN_COMPATIBILITY_2 + bool details = false); protected: // this executes a simple ftp command with the given argument and returns - // TRUE if it its return code starts with '2' + // true if it its return code starts with '2' bool DoSimpleCommand(const wxChar *command, const wxString& arg = wxEmptyString); // get the server reply, return the first character of the reply code, - // '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occured + // '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occurred char GetResult(); // check that the result is equal to expected value bool CheckResult(char ch) { return GetResult() == ch; } - wxSocketClient *GetPort(); + // return the socket to be used, Passive/Active versions are used only by + // GetPort() + wxSocketBase *GetPort(); + wxSocketBase *GetPassivePort(); + wxSocketBase *GetActivePort(); + + // helper for GetPort() + wxString GetPortCmdArgument(const wxIPV4address& Local, const wxIPV4address& New); + + // accept connection from server in active mode, returns the same socket as + // passed in passive mode + wxSocketBase *AcceptIfActive(wxSocketBase *sock); - wxString m_user, - m_passwd; - wxString m_lastResult; - wxProtocolError m_lastError; + // internal variables: + + wxString m_lastResult; // true if there is an FTP transfer going on - bool m_streaming; + bool m_streaming; // although this should be set to ASCII by default according to STD9, // we will use BINARY transfer mode by default for backwards compatibility - TransferMode m_currentTransfermode; + TransferMode m_currentTransfermode; + + bool m_bPassive; + + // following is true when a read or write times out, we then assume + // the connection is dead and abort. we avoid additional delays this way + bool m_bEncounteredError; + friend class wxInputFTPStream; friend class wxOutputFTPStream; @@ -162,7 +170,7 @@ protected: // the trace mask used by assorted wxLogTrace() in ftp code, do // wxLog::AddTraceMask(FTP_TRACE_MASK) to see them in output -#define FTP_TRACE_MASK _T("ftp") +#define FTP_TRACE_MASK wxT("ftp") #endif // wxUSE_PROTOCOL_FTP