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 /////////////////////////////////////////////////////////////////////////////
18 #if wxUSE_PROTOCOL_FTP
20 #include "wx/sckaddr.h"
21 #include "wx/protocol/protocol.h"
24 class WXDLLIMPEXP_NET wxFTP
: public wxProtocol
29 NONE
, // not set by user explicitly
37 // Connecting and disconnecting
38 bool Connect(const wxSockAddress
& addr
, bool wait
= true);
39 bool Connect(const wxString
& host
);
46 // set transfer mode now
47 void SetPassive(bool pasv
) { m_bPassive
= pasv
; }
48 bool SetBinary() { return SetTransferMode(BINARY
); }
49 bool SetAscii() { return SetTransferMode(ASCII
); }
50 bool SetTransferMode(TransferMode mode
);
52 // Generic FTP interface
54 // FTP doesn't know the MIME type of the last downloaded/uploaded file
55 virtual wxString
GetContentType() const { return wxEmptyString
; }
57 // the last FTP server reply
58 const wxString
& GetLastResult() const { return m_lastResult
; }
60 // send any FTP command (should be full FTP command line but without
61 // trailing "\r\n") and return its return code
62 char SendCommand(const wxString
& command
);
64 // check that the command returned the given code
65 bool CheckCommand(const wxString
& command
, char expectedReturn
)
67 // SendCommand() does updates m_lastError
68 return SendCommand(command
) == expectedReturn
;
71 // Filesystem commands
72 bool ChDir(const wxString
& dir
);
73 bool MkDir(const wxString
& dir
);
74 bool RmDir(const wxString
& dir
);
76 bool Rename(const wxString
& src
, const wxString
& dst
);
77 bool RmFile(const wxString
& path
);
79 // Get the size of a file in the current dir.
80 // this function tries its best to deliver the size in bytes using BINARY
81 // (the SIZE command reports different sizes depending on whether
82 // type is set to ASCII or BINARY)
83 // returns -1 if file is non-existant or size could not be found
84 int GetFileSize(const wxString
& fileName
);
86 // Check to see if a file exists in the current dir
87 bool FileExists(const wxString
& fileName
);
92 virtual wxInputStream
*GetInputStream(const wxString
& path
);
93 virtual wxOutputStream
*GetOutputStream(const wxString
& path
);
97 // get the list of full filenames, the format is fixed: one file name per
99 bool GetFilesList(wxArrayString
& files
,
100 const wxString
& wildcard
= wxEmptyString
)
102 return GetList(files
, wildcard
, false);
105 // get a directory list in server dependent format - this can be shown
106 // directly to the user
107 bool GetDirList(wxArrayString
& files
,
108 const wxString
& wildcard
= wxEmptyString
)
110 return GetList(files
, wildcard
, true);
113 // equivalent to either GetFilesList() (default) or GetDirList()
114 bool GetList(wxArrayString
& files
,
115 const wxString
& wildcard
= wxEmptyString
,
116 bool details
= false);
119 // this executes a simple ftp command with the given argument and returns
120 // true if it its return code starts with '2'
121 bool DoSimpleCommand(const wxChar
*command
,
122 const wxString
& arg
= wxEmptyString
);
124 // get the server reply, return the first character of the reply code,
125 // '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occurred
128 // check that the result is equal to expected value
129 bool CheckResult(char ch
) { return GetResult() == ch
; }
131 // return the socket to be used, Passive/Active versions are used only by
133 wxSocketBase
*GetPort();
134 wxSocketBase
*GetPassivePort();
135 wxSocketBase
*GetActivePort();
137 // helper for GetPort()
138 wxString
GetPortCmdArgument(const wxIPV4address
& Local
, const wxIPV4address
& New
);
140 // accept connection from server in active mode, returns the same socket as
141 // passed in in passive mode
142 wxSocketBase
*AcceptIfActive(wxSocketBase
*sock
);
145 // internal variables:
147 wxString m_lastResult
;
149 // true if there is an FTP transfer going on
152 // although this should be set to ASCII by default according to STD9,
153 // we will use BINARY transfer mode by default for backwards compatibility
154 TransferMode m_currentTransfermode
;
158 // following is true when a read or write times out, we then assume
159 // the connection is dead and abort. we avoid additional delays this way
160 bool m_bEncounteredError
;
163 friend class wxInputFTPStream
;
164 friend class wxOutputFTPStream
;
166 DECLARE_DYNAMIC_CLASS_NO_COPY(wxFTP
)
167 DECLARE_PROTOCOL(wxFTP
)
170 // the trace mask used by assorted wxLogTrace() in ftp code, do
171 // wxLog::AddTraceMask(FTP_TRACE_MASK) to see them in output
172 #define FTP_TRACE_MASK wxT("ftp")
174 #endif // wxUSE_PROTOCOL_FTP
176 #endif // __WX_FTP_H__