]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/protocol/ftp.h
in debug mode when clicking with the middle mouse button draw borders around all...
[wxWidgets.git] / include / wx / protocol / ftp.h
... / ...
CommitLineData
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 licence
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef __WX_FTP_H__
14#define __WX_FTP_H__
15
16#include "wx/defs.h"
17
18#if wxUSE_PROTOCOL_FTP
19
20#include "wx/sckaddr.h"
21#include "wx/protocol/protocol.h"
22#include "wx/url.h"
23
24class WXDLLIMPEXP_NET wxFTP : public wxProtocol
25{
26public:
27 enum TransferMode
28 {
29 NONE, // not set by user explicitly
30 ASCII,
31 BINARY
32 };
33
34 wxFTP();
35 virtual ~wxFTP();
36
37 // Connecting and disconnecting
38 bool Connect(const wxSockAddress& addr, bool wait = true);
39 bool Connect(const wxString& host);
40
41 // disconnect
42 virtual bool Close();
43
44 // Parameters set up
45
46 // set transfer mode now
47 void SetPassive(bool pasv) { m_bPassive = pasv; }
48 bool SetBinary() { return SetTransferMode(BINARY); }
49 bool SetAscii() { return SetTransferMode(ASCII); }
50 bool SetTransferMode(TransferMode mode);
51
52 // Generic FTP interface
53
54 // FTP doesn't know the MIME type of the last downloaded/uploaded file
55 virtual wxString GetContentType() const { return wxEmptyString; }
56
57 // the last FTP server reply
58 const wxString& GetLastResult() const { return m_lastResult; }
59
60 // send any FTP command (should be full FTP command line but without
61 // trailing "\r\n") and return its return code
62 char SendCommand(const wxString& command);
63
64 // check that the command returned the given code
65 bool CheckCommand(const wxString& command, char expectedReturn)
66 {
67 // SendCommand() does updates m_lastError
68 return SendCommand(command) == expectedReturn;
69 }
70
71 // Filesystem commands
72 bool ChDir(const wxString& dir);
73 bool MkDir(const wxString& dir);
74 bool RmDir(const wxString& dir);
75 wxString Pwd();
76 bool Rename(const wxString& src, const wxString& dst);
77 bool RmFile(const wxString& path);
78
79 // Get the size of a file in the current dir.
80 // this function tries its best to deliver the size in bytes using BINARY
81 // (the SIZE command reports different sizes depending on whether
82 // type is set to ASCII or BINARY)
83 // returns -1 if file is non-existant or size could not be found
84 int GetFileSize(const wxString& fileName);
85
86 // Check to see if a file exists in the current dir
87 bool FileExists(const wxString& fileName);
88
89 // Download methods
90 bool Abort();
91
92 virtual wxInputStream *GetInputStream(const wxString& path);
93 virtual wxOutputStream *GetOutputStream(const wxString& path);
94
95 // Directory listing
96
97 // get the list of full filenames, the format is fixed: one file name per
98 // line
99 bool GetFilesList(wxArrayString& files,
100 const wxString& wildcard = wxEmptyString)
101 {
102 return GetList(files, wildcard, false);
103 }
104
105 // get a directory list in server dependent format - this can be shown
106 // directly to the user
107 bool GetDirList(wxArrayString& files,
108 const wxString& wildcard = wxEmptyString)
109 {
110 return GetList(files, wildcard, true);
111 }
112
113 // equivalent to either GetFilesList() (default) or GetDirList()
114 bool GetList(wxArrayString& files,
115 const wxString& wildcard = wxEmptyString,
116 bool details = false);
117
118protected:
119 // this executes a simple ftp command with the given argument and returns
120 // true if it its return code starts with '2'
121 bool DoSimpleCommand(const wxChar *command,
122 const wxString& arg = wxEmptyString);
123
124 // get the server reply, return the first character of the reply code,
125 // '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occurred
126 char GetResult();
127
128 // check that the result is equal to expected value
129 bool CheckResult(char ch) { return GetResult() == ch; }
130
131 // return the socket to be used, Passive/Active versions are used only by
132 // GetPort()
133 wxSocketBase *GetPort();
134 wxSocketBase *GetPassivePort();
135 wxSocketBase *GetActivePort();
136
137 // helper for GetPort()
138 wxString GetPortCmdArgument(const wxIPV4address& Local, const wxIPV4address& New);
139
140 // accept connection from server in active mode, returns the same socket as
141 // passed in in passive mode
142 wxSocketBase *AcceptIfActive(wxSocketBase *sock);
143
144
145 // internal variables:
146
147 wxString m_lastResult;
148
149 // true if there is an FTP transfer going on
150 bool m_streaming;
151
152 // although this should be set to ASCII by default according to STD9,
153 // we will use BINARY transfer mode by default for backwards compatibility
154 TransferMode m_currentTransfermode;
155
156 bool m_bPassive;
157
158 // following is true when a read or write times out, we then assume
159 // the connection is dead and abort. we avoid additional delays this way
160 bool m_bEncounteredError;
161
162
163 friend class wxInputFTPStream;
164 friend class wxOutputFTPStream;
165
166 DECLARE_DYNAMIC_CLASS_NO_COPY(wxFTP)
167 DECLARE_PROTOCOL(wxFTP)
168};
169
170// the trace mask used by assorted wxLogTrace() in ftp code, do
171// wxLog::AddTraceMask(FTP_TRACE_MASK) to see them in output
172#define FTP_TRACE_MASK _T("ftp")
173
174#endif // wxUSE_PROTOCOL_FTP
175
176#endif // __WX_FTP_H__