1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/protocol/ftp.h
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 virtual bool Connect(const wxSockAddress
& addr
, bool wait
= true);
39 virtual bool Connect(const wxString
& host
) { return Connect(host
, 0); }
40 virtual bool Connect(const wxString
& host
, unsigned short port
);
47 // set transfer mode now
48 void SetPassive(bool pasv
) { m_bPassive
= pasv
; }
49 bool SetBinary() { return SetTransferMode(BINARY
); }
50 bool SetAscii() { return SetTransferMode(ASCII
); }
51 bool SetTransferMode(TransferMode mode
);
53 // Generic FTP interface
55 // FTP doesn't know the MIME type of the last downloaded/uploaded file
56 virtual wxString
GetContentType() const { return wxEmptyString
; }
58 // the last FTP server reply
59 const wxString
& GetLastResult() const { return m_lastResult
; }
61 // send any FTP command (should be full FTP command line but without
62 // trailing "\r\n") and return its return code
63 char SendCommand(const wxString
& command
);
65 // check that the command returned the given code
66 bool CheckCommand(const wxString
& command
, char expectedReturn
)
68 // SendCommand() does updates m_lastError
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
);
80 // Get the size of a file in the current dir.
81 // this function tries its best to deliver the size in bytes using BINARY
82 // (the SIZE command reports different sizes depending on whether
83 // type is set to ASCII or BINARY)
84 // returns -1 if file is non-existent or size could not be found
85 int GetFileSize(const wxString
& fileName
);
87 // Check to see if a file exists in the current dir
88 bool FileExists(const wxString
& fileName
);
93 virtual wxInputStream
*GetInputStream(const wxString
& path
);
94 virtual wxOutputStream
*GetOutputStream(const wxString
& path
);
98 // get the list of full filenames, the format is fixed: one file name per
100 bool GetFilesList(wxArrayString
& files
,
101 const wxString
& wildcard
= wxEmptyString
)
103 return GetList(files
, wildcard
, false);
106 // get a directory list in server dependent format - this can be shown
107 // directly to the user
108 bool GetDirList(wxArrayString
& files
,
109 const wxString
& wildcard
= wxEmptyString
)
111 return GetList(files
, wildcard
, true);
114 // equivalent to either GetFilesList() (default) or GetDirList()
115 bool GetList(wxArrayString
& files
,
116 const wxString
& wildcard
= wxEmptyString
,
117 bool details
= false);
120 // this executes a simple ftp command with the given argument and returns
121 // true if it its return code starts with '2'
122 bool DoSimpleCommand(const wxChar
*command
,
123 const wxString
& arg
= wxEmptyString
);
125 // get the server reply, return the first character of the reply code,
126 // '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occurred
129 // check that the result is equal to expected value
130 bool CheckResult(char ch
) { return GetResult() == ch
; }
132 // return the socket to be used, Passive/Active versions are used only by
134 wxSocketBase
*GetPort();
135 wxSocketBase
*GetPassivePort();
136 wxSocketBase
*GetActivePort();
138 // helper for GetPort()
139 wxString
GetPortCmdArgument(const wxIPV4address
& Local
, const wxIPV4address
& New
);
141 // accept connection from server in active mode, returns the same socket as
142 // passed in passive mode
143 wxSocketBase
*AcceptIfActive(wxSocketBase
*sock
);
146 // internal variables:
148 wxString m_lastResult
;
150 // true if there is an FTP transfer going on
153 // although this should be set to ASCII by default according to STD9,
154 // we will use BINARY transfer mode by default for backwards compatibility
155 TransferMode m_currentTransfermode
;
159 // following is true when a read or write times out, we then assume
160 // the connection is dead and abort. we avoid additional delays this way
161 bool m_bEncounteredError
;
164 friend class wxInputFTPStream
;
165 friend class wxOutputFTPStream
;
167 DECLARE_DYNAMIC_CLASS_NO_COPY(wxFTP
)
168 DECLARE_PROTOCOL(wxFTP
)
171 // the trace mask used by assorted wxLogTrace() in ftp code, do
172 // wxLog::AddTraceMask(FTP_TRACE_MASK) to see them in output
173 #define FTP_TRACE_MASK wxT("ftp")
175 #endif // wxUSE_PROTOCOL_FTP
177 #endif // __WX_FTP_H__