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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/////////////////////////////////////////////////////////////////////////////
// Name:        ftp.h
// Purpose:     FTP protocol
// Author:      Vadim Zeitlin
// Modified by: Mark Johnson, wxWindows@mj10777.de 
//              20000917 : RmDir, GetLastResult, GetList
// Created:     07/07/1997
// RCS-ID:      $Id: ftp.h,v 1.21 2005/05/31 09:18:48 JS Exp $
// Copyright:   (c) 1997, 1998 Guilhem Lavaux
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef __WX_FTP_H__
#define __WX_FTP_H__

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
    #pragma interface "ftp.h"
#endif

#include "wx/defs.h"

#if wxUSE_PROTOCOL_FTP

#include "wx/sckaddr.h"
#include "wx/protocol/protocol.h"
#include "wx/url.h"

class WXDLLIMPEXP_NET wxFTP : public wxProtocol
{
public:
    enum TransferMode
    {
        NONE,       // not set by user explicitly
        ASCII,
        BINARY
    };

    wxFTP();
    virtual ~wxFTP();

    // Connecting and disconnecting
    void SetUser(const wxString& user) { m_user = user; }
    void SetPassword(const wxString& passwd) { m_passwd = passwd; }

    bool Connect(wxSockAddress& addr, bool wait = true);
    bool Connect(const wxString& host);

    // disconnect
    virtual bool Close();

    // Parameters set up

    // set transfer mode now
    void SetPassive(bool pasv) { m_bPassive = pasv; };
    void SetDefaultTimeout(wxUint32 Value);
    bool SetBinary() { return SetTransferMode(BINARY); }
    bool SetAscii() { return SetTransferMode(ASCII); }
    bool SetTransferMode(TransferMode mode);

    // Generic FTP interface

    // the error code
    virtual wxProtocolError GetError() { return m_lastError; }

    // the last FTP server reply
    const wxString& GetLastResult() { return m_lastResult; }

    // send any FTP command (should be full FTP command line but without
    // trailing "\r\n") and return its return code
    char SendCommand(const wxString& command);

    // check that the command returned the given code
    bool CheckCommand(const wxString& command, char expectedReturn)
    {
        return SendCommand(command) == expectedReturn;
    }

    // Filesystem commands
    bool ChDir(const wxString& dir);
    bool MkDir(const wxString& dir);
    bool RmDir(const wxString& dir);
    wxString Pwd();
    bool Rename(const wxString& src, const wxString& dst);
    bool RmFile(const wxString& path);

    // Get the size of a file in the current dir.
    // this function tries its best to deliver the size in bytes using BINARY
    // (the SIZE command reports different sizes depending on whether 
    // type is set to ASCII or BINARY)
    // returns -1 if file is non-existant or size could not be found
    int GetFileSize(const wxString& fileName);

       // Check to see if a file exists in the current dir
    bool FileExists(const wxString& fileName);

    // Download methods
    bool Abort();

    virtual wxInputStream *GetInputStream(const wxString& path);
    virtual wxOutputStream *GetOutputStream(const wxString& path);

    // Directory listing

    // get the list of full filenames, the format is fixed: one file name per
    // line
    bool GetFilesList(wxArrayString& files,
                      const wxString& wildcard = wxEmptyString)
    {
        return GetList(files, wildcard, false);
    }

    // get a directory list in server dependent format - this can be shown
    // directly to the user
    bool GetDirList(wxArrayString& files,
                    const wxString& wildcard = wxEmptyString)
    {
        return GetList(files, wildcard, true);
    }

    // equivalent to either GetFilesList() (default) or GetDirList()
    bool GetList(wxArrayString& files,
                 const wxString& wildcard = wxEmptyString,
                 bool details = false);

protected:
    // this executes a simple ftp command with the given argument and returns
    // true if it its return code starts with '2'
    bool DoSimpleCommand(const wxChar *command,
                         const wxString& arg = wxEmptyString);

    // get the server reply, return the first character of the reply code,
    // '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occurred
    char GetResult();

    // check that the result is equal to expected value
    bool CheckResult(char ch) { return GetResult() == ch; }

    // return the socket to be used, Passive/Active versions are used only by
    // GetPort()
    wxSocketBase *GetPort();
    wxSocketBase *GetPassivePort();
    wxSocketBase *GetActivePort();

    // helper for GetPort()
    wxString GetPortCmdArgument(wxIPV4address Local, wxIPV4address New);

    // accept connection from server in active mode, returns the same socket as
    // passed in in passive mode
    wxSocketBase *AcceptIfActive(wxSocketBase *sock);


    wxString m_user,
             m_passwd;

    wxString m_lastResult;
    wxProtocolError m_lastError;

    // true if there is an FTP transfer going on
    bool m_streaming;

    // although this should be set to ASCII by default according to STD9,
    // we will use BINARY transfer mode by default for backwards compatibility
    TransferMode m_currentTransfermode;

    friend class wxInputFTPStream;
    friend class wxOutputFTPStream;

    bool            m_bPassive;
    wxUint32        m_uiDefaultTimeout;

    // following is true when  a read or write times out, we then assume
    // the connection is dead and abort. we avoid additional delays this way
    bool            m_bEncounteredError;


    DECLARE_DYNAMIC_CLASS_NO_COPY(wxFTP)
    DECLARE_PROTOCOL(wxFTP)
};

// the trace mask used by assorted wxLogTrace() in ftp code, do
// wxLog::AddTraceMask(FTP_TRACE_MASK) to see them in output
#define FTP_TRACE_MASK _T("ftp")

#endif // wxUSE_PROTOCOL_FTP

#endif // __WX_FTP_H__