1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: FTP protocol
4 // Author: Vadim Zeitlin
5 // Modified by: Mark Johnson, wxWindows@mj10777.de
6 // 20000917 : RmDir, GetLastResult, GetList
9 // Copyright: (c) 1997, 1998 Guilhem Lavaux
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma interface "ftp.h"
22 #if wxUSE_PROTOCOL_FTP
24 #include "wx/sckaddr.h"
25 #include "wx/protocol/protocol.h"
28 class WXDLLIMPEXP_NET wxFTP
: public wxProtocol
33 NONE
, // not set by user explicitly
41 // Connecting and disconnecting
42 void SetUser(const wxString
& user
) { m_user
= user
; }
43 void SetPassword(const wxString
& passwd
) { m_passwd
= passwd
; }
45 bool Connect(wxSockAddress
& addr
, bool wait
= TRUE
);
46 bool Connect(const wxString
& host
);
53 // set transfer mode now
54 bool SetBinary() { return SetTransferMode(BINARY
); }
55 bool SetAscii() { return SetTransferMode(ASCII
); }
56 bool SetTransferMode(TransferMode mode
);
58 // Generic FTP interface
61 virtual wxProtocolError
GetError() { return m_lastError
; }
63 // the last FTP server reply
64 const wxString
& GetLastResult() { return m_lastResult
; }
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
);
70 // check that the command returned the given code
71 bool CheckCommand(const wxString
& command
, char expectedReturn
)
73 return SendCommand(command
) == expectedReturn
;
76 // Filesystem commands
77 bool ChDir(const wxString
& dir
);
78 bool MkDir(const wxString
& dir
);
79 bool RmDir(const wxString
& dir
);
81 bool Rename(const wxString
& src
, const wxString
& dst
);
82 bool RmFile(const wxString
& path
);
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
);
91 // Check to see if a file exists in the current dir
92 bool FileExists(const wxString
& fileName
);
97 virtual wxInputStream
*GetInputStream(const wxString
& path
);
98 virtual wxOutputStream
*GetOutputStream(const wxString
& path
);
102 // get the list of full filenames, the format is fixed: one file name per
104 bool GetFilesList(wxArrayString
& files
,
105 const wxString
& wildcard
= wxEmptyString
)
107 return GetList(files
, wildcard
, FALSE
);
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
)
115 return GetList(files
, wildcard
, TRUE
);
118 // equivalent to either GetFilesList() (default) or GetDirList()
119 bool GetList(wxArrayString
& files
,
120 const wxString
& wildcard
= wxEmptyString
,
121 bool details
= FALSE
);
124 // this executes a simple ftp command with the given argument and returns
125 // TRUE if it its return code starts with '2'
126 bool DoSimpleCommand(const wxChar
*command
,
127 const wxString
& arg
= wxEmptyString
);
129 // get the server reply, return the first character of the reply code,
130 // '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occured
133 // check that the result is equal to expected value
134 bool CheckResult(char ch
) { return GetResult() == ch
; }
136 wxSocketClient
*GetPort();
141 wxString m_lastResult
;
142 wxProtocolError m_lastError
;
144 // true if there is an FTP transfer going on
147 // although this should be set to ASCII by default according to STD9,
148 // we will use BINARY transfer mode by default for backwards compatibility
149 TransferMode m_currentTransfermode
;
151 friend class wxInputFTPStream
;
152 friend class wxOutputFTPStream
;
154 DECLARE_DYNAMIC_CLASS_NO_COPY(wxFTP
)
155 DECLARE_PROTOCOL(wxFTP
)
158 // the trace mask used by assorted wxLogTrace() in ftp code, do
159 // wxLog::AddTraceMask(FTP_TRACE_MASK) to see them in output
160 #define FTP_TRACE_MASK _T("ftp")
162 #endif // wxUSE_PROTOCOL_FTP
164 #endif // __WX_FTP_H__