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 license
11 /////////////////////////////////////////////////////////////////////////////
20 #include "wx/object.h"
21 #include "wx/sckaddr.h"
22 #include "wx/protocol/protocol.h"
25 class WXDLLEXPORT wxFTP
: public wxProtocol
37 // Connecting and disconnecting
38 void SetUser(const wxString
& user
) { m_user
= user
; }
39 void SetPassword(const wxString
& passwd
) { m_passwd
= passwd
; }
41 bool Connect(wxSockAddress
& addr
, bool wait
= TRUE
);
42 bool Connect(const wxString
& host
);
49 // set transfer mode now
50 bool SetBinary() { return SetTransferMode(BINARY
); }
51 bool SetAscii() { return SetTransferMode(ASCII
); }
52 bool SetTransferMode(TransferMode mode
);
54 // Generic FTP interface
57 virtual wxProtocolError
GetError() { return m_lastError
; }
59 // the last FTP server reply
60 const wxString
& GetLastResult() { return m_lastResult
; }
62 // send any FTP command (should be full FTP command line but without
63 // trailing "\r\n") and return its return code
64 char SendCommand(const wxString
& command
);
66 // check that the command returned the given code
67 bool CheckCommand(const wxString
& command
, char expectedReturn
)
69 return SendCommand(command
) == expectedReturn
;
72 // Filesystem commands
73 bool ChDir(const wxString
& dir
);
74 bool MkDir(const wxString
& dir
);
75 bool RmDir(const wxString
& dir
);
77 bool Rename(const wxString
& src
, const wxString
& dst
);
78 bool RmFile(const wxString
& path
);
83 virtual wxInputStream
*GetInputStream(const wxString
& path
);
84 virtual wxOutputStream
*GetOutputStream(const wxString
& path
);
88 // get the list of full filenames, the format is fixed: one file name per
90 bool GetFilesList(wxArrayString
& files
,
91 const wxString
& wildcard
= wxEmptyString
)
93 return GetList(files
, wildcard
, FALSE
);
96 // get a directory list in server dependent format - this can be shown
97 // directly to the user
98 bool GetDirList(wxArrayString
& files
,
99 const wxString
& wildcard
= wxEmptyString
)
101 return GetList(files
, wildcard
, TRUE
);
104 // equivalent to either GetFilesList() (default) or GetDirList()
105 bool GetList(wxArrayString
& files
,
106 const wxString
& wildcard
= wxEmptyString
,
107 bool details
= FALSE
);
109 #ifdef WXWIN_COMPATIBILITY_2
111 wxList
*GetList(const wxString
& wildcard
, bool details
= FALSE
);
112 #endif // WXWIN_COMPATIBILITY_2
115 // this executes a simple ftp command with the given argument and returns
116 // TRUE if it its return code starts with '2'
117 bool DoSimpleCommand(const wxChar
*command
,
118 const wxString
& arg
= wxEmptyString
);
120 // get the server reply, return the first character of the reply code,
121 // '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occured
124 // check that the result is equal to expected value
125 bool CheckResult(char ch
) { return GetResult() == ch
; }
127 wxSocketClient
*GetPort();
132 wxString m_lastResult
;
133 wxProtocolError m_lastError
;
135 // true if there is an FTP transfer going on
138 // true if the user had set the transfer mode
141 friend class wxInputFTPStream
;
142 friend class wxOutputFTPStream
;
144 DECLARE_DYNAMIC_CLASS(wxFTP
)
145 DECLARE_PROTOCOL(wxFTP
)
148 #endif // __WX_FTP_H__