~ubuntu-dev/wxwidgets2.6/upstream-debian

« back to all changes in this revision

Viewing changes to include/wx/protocol/ftp.h

  • Committer: Daniel T Chen
  • Date: 2006-06-26 10:15:11 UTC
  • Revision ID: crimsun@ubuntu.com-20060626101511-a4436cec4c6d9b35
ImportĀ DebianĀ 2.6.3.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: ftp.h,v 1.21 2005/05/31 09:18:48 JS Exp $
 
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
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 
17
    #pragma interface "ftp.h"
 
18
#endif
 
19
 
 
20
#include "wx/defs.h"
 
21
 
 
22
#if wxUSE_PROTOCOL_FTP
 
23
 
 
24
#include "wx/sckaddr.h"
 
25
#include "wx/protocol/protocol.h"
 
26
#include "wx/url.h"
 
27
 
 
28
class WXDLLIMPEXP_NET wxFTP : public wxProtocol
 
29
{
 
30
public:
 
31
    enum TransferMode
 
32
    {
 
33
        NONE,       // not set by user explicitly
 
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
    void SetPassive(bool pasv) { m_bPassive = pasv; };
 
55
    void SetDefaultTimeout(wxUint32 Value);
 
56
    bool SetBinary() { return SetTransferMode(BINARY); }
 
57
    bool SetAscii() { return SetTransferMode(ASCII); }
 
58
    bool SetTransferMode(TransferMode mode);
 
59
 
 
60
    // Generic FTP interface
 
61
 
 
62
    // the error code
 
63
    virtual wxProtocolError GetError() { return m_lastError; }
 
64
 
 
65
    // the last FTP server reply
 
66
    const wxString& GetLastResult() { return m_lastResult; }
 
67
 
 
68
    // send any FTP command (should be full FTP command line but without
 
69
    // trailing "\r\n") and return its return code
 
70
    char SendCommand(const wxString& command);
 
71
 
 
72
    // check that the command returned the given code
 
73
    bool CheckCommand(const wxString& command, char expectedReturn)
 
74
    {
 
75
        return SendCommand(command) == expectedReturn;
 
76
    }
 
77
 
 
78
    // Filesystem commands
 
79
    bool ChDir(const wxString& dir);
 
80
    bool MkDir(const wxString& dir);
 
81
    bool RmDir(const wxString& dir);
 
82
    wxString Pwd();
 
83
    bool Rename(const wxString& src, const wxString& dst);
 
84
    bool RmFile(const wxString& path);
 
85
 
 
86
    // Get the size of a file in the current dir.
 
87
    // this function tries its best to deliver the size in bytes using BINARY
 
88
    // (the SIZE command reports different sizes depending on whether 
 
89
    // type is set to ASCII or BINARY)
 
90
    // returns -1 if file is non-existant or size could not be found
 
91
    int GetFileSize(const wxString& fileName);
 
92
 
 
93
       // Check to see if a file exists in the current dir
 
94
    bool FileExists(const wxString& fileName);
 
95
 
 
96
    // Download methods
 
97
    bool Abort();
 
98
 
 
99
    virtual wxInputStream *GetInputStream(const wxString& path);
 
100
    virtual wxOutputStream *GetOutputStream(const wxString& path);
 
101
 
 
102
    // Directory listing
 
103
 
 
104
    // get the list of full filenames, the format is fixed: one file name per
 
105
    // line
 
106
    bool GetFilesList(wxArrayString& files,
 
107
                      const wxString& wildcard = wxEmptyString)
 
108
    {
 
109
        return GetList(files, wildcard, false);
 
110
    }
 
111
 
 
112
    // get a directory list in server dependent format - this can be shown
 
113
    // directly to the user
 
114
    bool GetDirList(wxArrayString& files,
 
115
                    const wxString& wildcard = wxEmptyString)
 
116
    {
 
117
        return GetList(files, wildcard, true);
 
118
    }
 
119
 
 
120
    // equivalent to either GetFilesList() (default) or GetDirList()
 
121
    bool GetList(wxArrayString& files,
 
122
                 const wxString& wildcard = wxEmptyString,
 
123
                 bool details = false);
 
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 occurred
 
133
    char GetResult();
 
134
 
 
135
    // check that the result is equal to expected value
 
136
    bool CheckResult(char ch) { return GetResult() == ch; }
 
137
 
 
138
    // return the socket to be used, Passive/Active versions are used only by
 
139
    // GetPort()
 
140
    wxSocketBase *GetPort();
 
141
    wxSocketBase *GetPassivePort();
 
142
    wxSocketBase *GetActivePort();
 
143
 
 
144
    // helper for GetPort()
 
145
    wxString GetPortCmdArgument(wxIPV4address Local, wxIPV4address New);
 
146
 
 
147
    // accept connection from server in active mode, returns the same socket as
 
148
    // passed in in passive mode
 
149
    wxSocketBase *AcceptIfActive(wxSocketBase *sock);
 
150
 
 
151
 
 
152
    wxString m_user,
 
153
             m_passwd;
 
154
 
 
155
    wxString m_lastResult;
 
156
    wxProtocolError m_lastError;
 
157
 
 
158
    // true if there is an FTP transfer going on
 
159
    bool m_streaming;
 
160
 
 
161
    // although this should be set to ASCII by default according to STD9,
 
162
    // we will use BINARY transfer mode by default for backwards compatibility
 
163
    TransferMode m_currentTransfermode;
 
164
 
 
165
    friend class wxInputFTPStream;
 
166
    friend class wxOutputFTPStream;
 
167
 
 
168
    bool            m_bPassive;
 
169
    wxUint32        m_uiDefaultTimeout;
 
170
 
 
171
    // following is true when  a read or write times out, we then assume
 
172
    // the connection is dead and abort. we avoid additional delays this way
 
173
    bool            m_bEncounteredError;
 
174
 
 
175
 
 
176
    DECLARE_DYNAMIC_CLASS_NO_COPY(wxFTP)
 
177
    DECLARE_PROTOCOL(wxFTP)
 
178
};
 
179
 
 
180
// the trace mask used by assorted wxLogTrace() in ftp code, do
 
181
// wxLog::AddTraceMask(FTP_TRACE_MASK) to see them in output
 
182
#define FTP_TRACE_MASK _T("ftp")
 
183
 
 
184
#endif // wxUSE_PROTOCOL_FTP
 
185
 
 
186
#endif // __WX_FTP_H__