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