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