]> git.saurik.com Git - wxWidgets.git/blob - include/wx/protocol/ftp.h
added wx/defs.h include to correct compilation issues under Mac OS X
[wxWidgets.git] / include / wx / protocol / ftp.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: ftp.h
3 // Purpose: FTP protocol
4 // Author: Vadim Zeitlin
5 // Modified by: Mark Johnson, wxWindows@mj10777.de
6 // 20000917 : RmDir, GetLastResult, GetList
7 // Created: 07/07/1997
8 // RCS-ID: $Id$
9 // Copyright: (c) 1997, 1998 Guilhem Lavaux
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef __WX_FTP_H__
14 #define __WX_FTP_H__
15
16 #ifdef __GNUG__
17 #pragma interface "ftp.h"
18 #endif
19
20 #include "wx/object.h"
21 #include "wx/sckaddr.h"
22 #include "wx/protocol/protocol.h"
23 #include "wx/url.h"
24
25 class WXDLLEXPORT wxFTP : public wxProtocol
26 {
27 public:
28 enum TransferMode
29 {
30 NONE, // not set by user explicitly
31 ASCII,
32 BINARY
33 };
34
35 wxFTP();
36 virtual ~wxFTP();
37
38 // Connecting and disconnecting
39 void SetUser(const wxString& user) { m_user = user; }
40 void SetPassword(const wxString& passwd) { m_passwd = passwd; }
41
42 bool Connect(wxSockAddress& addr, bool wait = TRUE);
43 bool Connect(const wxString& host);
44
45 // disconnect
46 virtual bool Close();
47
48 // Parameters set up
49
50 // set transfer mode now
51 bool SetBinary() { return SetTransferMode(BINARY); }
52 bool SetAscii() { return SetTransferMode(ASCII); }
53 bool SetTransferMode(TransferMode mode);
54
55 // Generic FTP interface
56
57 // the error code
58 virtual wxProtocolError GetError() { return m_lastError; }
59
60 // the last FTP server reply
61 const wxString& GetLastResult() { return m_lastResult; }
62
63 // send any FTP command (should be full FTP command line but without
64 // trailing "\r\n") and return its return code
65 char SendCommand(const wxString& command);
66
67 // check that the command returned the given code
68 bool CheckCommand(const wxString& command, char expectedReturn)
69 {
70 return SendCommand(command) == expectedReturn;
71 }
72
73 // Filesystem commands
74 bool ChDir(const wxString& dir);
75 bool MkDir(const wxString& dir);
76 bool RmDir(const wxString& dir);
77 wxString Pwd();
78 bool Rename(const wxString& src, const wxString& dst);
79 bool RmFile(const wxString& path);
80
81 // Get the size of a file in the current dir.
82 // this function tries its best to deliver the size in bytes using BINARY
83 // (the SIZE command reports different sizes depending on whether
84 // type is set to ASCII or BINARY)
85 // returns -1 if file is non-existant or size could not be found
86 int GetFileSize(const wxString& fileName);
87
88 // Check to see if a file exists in the current dir
89 bool FileExists(const wxString& fileName);
90
91 // Download methods
92 bool Abort();
93
94 virtual wxInputStream *GetInputStream(const wxString& path);
95 virtual wxOutputStream *GetOutputStream(const wxString& path);
96
97 // Directory listing
98
99 // get the list of full filenames, the format is fixed: one file name per
100 // line
101 bool GetFilesList(wxArrayString& files,
102 const wxString& wildcard = wxEmptyString)
103 {
104 return GetList(files, wildcard, FALSE);
105 }
106
107 // get a directory list in server dependent format - this can be shown
108 // directly to the user
109 bool GetDirList(wxArrayString& files,
110 const wxString& wildcard = wxEmptyString)
111 {
112 return GetList(files, wildcard, TRUE);
113 }
114
115 // equivalent to either GetFilesList() (default) or GetDirList()
116 bool GetList(wxArrayString& files,
117 const wxString& wildcard = wxEmptyString,
118 bool details = FALSE);
119
120 #if WXWIN_COMPATIBILITY_2
121 // deprecated
122 wxList *GetList(const wxString& wildcard, bool details = FALSE);
123 #endif // WXWIN_COMPATIBILITY_2
124
125 protected:
126 // this executes a simple ftp command with the given argument and returns
127 // TRUE if it its return code starts with '2'
128 bool DoSimpleCommand(const wxChar *command,
129 const wxString& arg = wxEmptyString);
130
131 // get the server reply, return the first character of the reply code,
132 // '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occured
133 char GetResult();
134
135 // check that the result is equal to expected value
136 bool CheckResult(char ch) { return GetResult() == ch; }
137
138 wxSocketClient *GetPort();
139
140 wxString m_user,
141 m_passwd;
142
143 wxString m_lastResult;
144 wxProtocolError m_lastError;
145
146 // true if there is an FTP transfer going on
147 bool m_streaming;
148
149 // although this should be set to ASCII by default according to STD9,
150 // we will use BINARY transfer mode by default for backwards compatibility
151 TransferMode m_currentTransfermode;
152
153 friend class wxInputFTPStream;
154 friend class wxOutputFTPStream;
155
156 DECLARE_DYNAMIC_CLASS(wxFTP)
157 DECLARE_PROTOCOL(wxFTP)
158 };
159
160 // the trace mask used by assorted wxLogTrace() in ftp code, do
161 // wxLog::AddTraceMask(FTP_TRACE_MASK) to see them in output
162 #define FTP_TRACE_MASK _T("ftp")
163
164 #endif // __WX_FTP_H__