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 /////////////////////////////////////////////////////////////////////////////
17 #pragma interface "ftp.h"
20 #include "wx/object.h"
21 #include "wx/sckaddr.h"
22 #include "wx/protocol/protocol.h"
25 class WXDLLEXPORT wxFTP
: public wxProtocol
30 NONE
, // not set by user explicitly
38 // Connecting and disconnecting
39 void SetUser(const wxString
& user
) { m_user
= user
; }
40 void SetPassword(const wxString
& passwd
) { m_passwd
= passwd
; }
42 bool Connect(wxSockAddress
& addr
, bool wait
= TRUE
);
43 bool Connect(const wxString
& host
);
50 // set transfer mode now
51 bool SetBinary() { return SetTransferMode(BINARY
); }
52 bool SetAscii() { return SetTransferMode(ASCII
); }
53 bool SetTransferMode(TransferMode mode
);
55 // Generic FTP interface
58 virtual wxProtocolError
GetError() { return m_lastError
; }
60 // the last FTP server reply
61 const wxString
& GetLastResult() { return m_lastResult
; }
63 // send any FTP command (should be full FTP command line but without
64 // trailing "\r\n") and return its return code
65 char SendCommand(const wxString
& command
);
67 // check that the command returned the given code
68 bool CheckCommand(const wxString
& command
, char expectedReturn
)
70 return SendCommand(command
) == expectedReturn
;
73 // Filesystem commands
74 bool ChDir(const wxString
& dir
);
75 bool MkDir(const wxString
& dir
);
76 bool RmDir(const wxString
& dir
);
78 bool Rename(const wxString
& src
, const wxString
& dst
);
79 bool RmFile(const wxString
& path
);
81 // Get the size of a file in the current dir.
82 // this function tries its best to deliver the size in bytes using BINARY
83 // (the SIZE command reports different sizes depending on whether
84 // type is set to ASCII or BINARY)
85 // returns -1 if file is non-existant or size could not be found
86 int GetFileSize(const wxString
& fileName
);
88 // Check to see if a file exists in the current dir
89 bool FileExists(const wxString
& fileName
);
94 virtual wxInputStream
*GetInputStream(const wxString
& path
);
95 virtual wxOutputStream
*GetOutputStream(const wxString
& path
);
99 // get the list of full filenames, the format is fixed: one file name per
101 bool GetFilesList(wxArrayString
& files
,
102 const wxString
& wildcard
= wxEmptyString
)
104 return GetList(files
, wildcard
, FALSE
);
107 // get a directory list in server dependent format - this can be shown
108 // directly to the user
109 bool GetDirList(wxArrayString
& files
,
110 const wxString
& wildcard
= wxEmptyString
)
112 return GetList(files
, wildcard
, TRUE
);
115 // equivalent to either GetFilesList() (default) or GetDirList()
116 bool GetList(wxArrayString
& files
,
117 const wxString
& wildcard
= wxEmptyString
,
118 bool details
= FALSE
);
120 #ifdef WXWIN_COMPATIBILITY_2
122 wxList
*GetList(const wxString
& wildcard
, bool details
= FALSE
);
123 #endif // WXWIN_COMPATIBILITY_2
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
);
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 occured
135 // check that the result is equal to expected value
136 bool CheckResult(char ch
) { return GetResult() == ch
; }
138 wxSocketClient
*GetPort();
143 wxString m_lastResult
;
144 wxProtocolError m_lastError
;
146 // true if there is an FTP transfer going on
149 // although this should be set to ASCII by default according to STD9,
150 // we will use BINARY transfer mode by default for backwards compatibility
151 TransferMode m_currentTransfermode
;
153 friend class wxInputFTPStream
;
154 friend class wxOutputFTPStream
;
156 DECLARE_DYNAMIC_CLASS(wxFTP
)
157 DECLARE_PROTOCOL(wxFTP
)
160 // the trace mask used by assorted wxLogTrace() in ftp code, do
161 // wxLog::AddTraceMask(FTP_TRACE_MASK) to see them in output
162 #define FTP_TRACE_MASK _T("ftp")
164 #endif // __WX_FTP_H__