1998-09-06 18:28:00 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: ftp.h
|
|
|
|
// Purpose: FTP protocol
|
|
|
|
// Author: Vadim Zeitlin
|
2000-12-19 16:56:27 +00:00
|
|
|
// Modified by: Mark Johnson, wxWindows@mj10777.de
|
2004-05-23 14:56:36 +00:00
|
|
|
// 20000917 : RmDir, GetLastResult, GetList
|
1998-09-06 18:28:00 +00:00
|
|
|
// Created: 07/07/1997
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-09-06 18:28:00 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2000-03-15 17:16:35 +00:00
|
|
|
|
1998-09-06 18:28:00 +00:00
|
|
|
#ifndef __WX_FTP_H__
|
|
|
|
#define __WX_FTP_H__
|
|
|
|
|
2001-12-30 22:27:24 +00:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_PROTOCOL_FTP
|
|
|
|
|
1998-09-06 18:28:00 +00:00
|
|
|
#include "wx/sckaddr.h"
|
|
|
|
#include "wx/protocol/protocol.h"
|
|
|
|
#include "wx/url.h"
|
|
|
|
|
2003-07-27 22:41:06 +00:00
|
|
|
class WXDLLIMPEXP_NET wxFTP : public wxProtocol
|
2000-03-15 17:16:35 +00:00
|
|
|
{
|
1998-09-06 18:28:00 +00:00
|
|
|
public:
|
2000-12-19 16:56:27 +00:00
|
|
|
enum TransferMode
|
|
|
|
{
|
2001-01-24 16:37:04 +00:00
|
|
|
NONE, // not set by user explicitly
|
2000-12-19 16:56:27 +00:00
|
|
|
ASCII,
|
|
|
|
BINARY
|
|
|
|
};
|
|
|
|
|
|
|
|
wxFTP();
|
|
|
|
virtual ~wxFTP();
|
|
|
|
|
|
|
|
// Connecting and disconnecting
|
|
|
|
void SetUser(const wxString& user) { m_user = user; }
|
|
|
|
void SetPassword(const wxString& passwd) { m_passwd = passwd; }
|
|
|
|
|
2004-09-18 14:24:49 +00:00
|
|
|
bool Connect(wxSockAddress& addr, bool wait = true);
|
2000-12-19 16:56:27 +00:00
|
|
|
bool Connect(const wxString& host);
|
|
|
|
|
|
|
|
// disconnect
|
|
|
|
virtual bool Close();
|
|
|
|
|
|
|
|
// Parameters set up
|
|
|
|
|
|
|
|
// set transfer mode now
|
2007-04-14 09:58:37 +00:00
|
|
|
void SetPassive(bool pasv) { m_bPassive = pasv; }
|
2004-09-18 14:24:49 +00:00
|
|
|
void SetDefaultTimeout(wxUint32 Value);
|
2000-12-19 16:56:27 +00:00
|
|
|
bool SetBinary() { return SetTransferMode(BINARY); }
|
|
|
|
bool SetAscii() { return SetTransferMode(ASCII); }
|
|
|
|
bool SetTransferMode(TransferMode mode);
|
|
|
|
|
|
|
|
// Generic FTP interface
|
|
|
|
|
|
|
|
// the error code
|
|
|
|
virtual wxProtocolError GetError() { return m_lastError; }
|
|
|
|
|
|
|
|
// the last FTP server reply
|
|
|
|
const wxString& GetLastResult() { return m_lastResult; }
|
|
|
|
|
|
|
|
// send any FTP command (should be full FTP command line but without
|
|
|
|
// trailing "\r\n") and return its return code
|
|
|
|
char SendCommand(const wxString& command);
|
|
|
|
|
|
|
|
// check that the command returned the given code
|
|
|
|
bool CheckCommand(const wxString& command, char expectedReturn)
|
|
|
|
{
|
|
|
|
return SendCommand(command) == expectedReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filesystem commands
|
|
|
|
bool ChDir(const wxString& dir);
|
|
|
|
bool MkDir(const wxString& dir);
|
|
|
|
bool RmDir(const wxString& dir);
|
|
|
|
wxString Pwd();
|
|
|
|
bool Rename(const wxString& src, const wxString& dst);
|
|
|
|
bool RmFile(const wxString& path);
|
|
|
|
|
2001-04-22 12:24:51 +00:00
|
|
|
// Get the size of a file in the current dir.
|
|
|
|
// this function tries its best to deliver the size in bytes using BINARY
|
|
|
|
// (the SIZE command reports different sizes depending on whether
|
|
|
|
// type is set to ASCII or BINARY)
|
|
|
|
// returns -1 if file is non-existant or size could not be found
|
|
|
|
int GetFileSize(const wxString& fileName);
|
2001-01-24 16:37:04 +00:00
|
|
|
|
|
|
|
// Check to see if a file exists in the current dir
|
2001-04-22 12:24:51 +00:00
|
|
|
bool FileExists(const wxString& fileName);
|
2001-01-24 16:37:04 +00:00
|
|
|
|
2000-12-19 16:56:27 +00:00
|
|
|
// Download methods
|
|
|
|
bool Abort();
|
|
|
|
|
|
|
|
virtual wxInputStream *GetInputStream(const wxString& path);
|
|
|
|
virtual wxOutputStream *GetOutputStream(const wxString& path);
|
|
|
|
|
|
|
|
// Directory listing
|
|
|
|
|
|
|
|
// get the list of full filenames, the format is fixed: one file name per
|
|
|
|
// line
|
|
|
|
bool GetFilesList(wxArrayString& files,
|
|
|
|
const wxString& wildcard = wxEmptyString)
|
|
|
|
{
|
2004-09-18 14:24:49 +00:00
|
|
|
return GetList(files, wildcard, false);
|
2000-12-19 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get a directory list in server dependent format - this can be shown
|
|
|
|
// directly to the user
|
|
|
|
bool GetDirList(wxArrayString& files,
|
|
|
|
const wxString& wildcard = wxEmptyString)
|
|
|
|
{
|
2004-09-18 14:24:49 +00:00
|
|
|
return GetList(files, wildcard, true);
|
2000-12-19 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// equivalent to either GetFilesList() (default) or GetDirList()
|
|
|
|
bool GetList(wxArrayString& files,
|
|
|
|
const wxString& wildcard = wxEmptyString,
|
2004-09-18 14:24:49 +00:00
|
|
|
bool details = false);
|
2000-12-19 16:56:27 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// this executes a simple ftp command with the given argument and returns
|
2004-09-18 14:24:49 +00:00
|
|
|
// true if it its return code starts with '2'
|
2000-12-19 16:56:27 +00:00
|
|
|
bool DoSimpleCommand(const wxChar *command,
|
|
|
|
const wxString& arg = wxEmptyString);
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2000-12-19 16:56:27 +00:00
|
|
|
// get the server reply, return the first character of the reply code,
|
2005-05-31 09:20:43 +00:00
|
|
|
// '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occurred
|
2000-12-19 16:56:27 +00:00
|
|
|
char GetResult();
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2000-12-19 16:56:27 +00:00
|
|
|
// check that the result is equal to expected value
|
|
|
|
bool CheckResult(char ch) { return GetResult() == ch; }
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2004-09-18 14:24:49 +00:00
|
|
|
// return the socket to be used, Passive/Active versions are used only by
|
|
|
|
// GetPort()
|
|
|
|
wxSocketBase *GetPort();
|
|
|
|
wxSocketBase *GetPassivePort();
|
|
|
|
wxSocketBase *GetActivePort();
|
|
|
|
|
|
|
|
// helper for GetPort()
|
2005-09-24 21:43:15 +00:00
|
|
|
wxString GetPortCmdArgument(const wxIPV4address& Local, const wxIPV4address& New);
|
2004-09-18 14:24:49 +00:00
|
|
|
|
|
|
|
// accept connection from server in active mode, returns the same socket as
|
|
|
|
// passed in in passive mode
|
|
|
|
wxSocketBase *AcceptIfActive(wxSocketBase *sock);
|
|
|
|
|
2000-03-15 17:16:35 +00:00
|
|
|
|
2000-12-19 16:56:27 +00:00
|
|
|
wxString m_user,
|
|
|
|
m_passwd;
|
2000-03-15 17:16:35 +00:00
|
|
|
|
2000-12-19 16:56:27 +00:00
|
|
|
wxString m_lastResult;
|
|
|
|
wxProtocolError m_lastError;
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2000-12-19 16:56:27 +00:00
|
|
|
// true if there is an FTP transfer going on
|
|
|
|
bool m_streaming;
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2001-01-24 16:37:04 +00:00
|
|
|
// although this should be set to ASCII by default according to STD9,
|
|
|
|
// we will use BINARY transfer mode by default for backwards compatibility
|
|
|
|
TransferMode m_currentTransfermode;
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2000-12-19 16:56:27 +00:00
|
|
|
friend class wxInputFTPStream;
|
|
|
|
friend class wxOutputFTPStream;
|
2000-03-15 17:16:35 +00:00
|
|
|
|
2004-09-18 14:24:49 +00:00
|
|
|
bool m_bPassive;
|
|
|
|
wxUint32 m_uiDefaultTimeout;
|
|
|
|
|
|
|
|
// following is true when a read or write times out, we then assume
|
|
|
|
// the connection is dead and abort. we avoid additional delays this way
|
|
|
|
bool m_bEncounteredError;
|
|
|
|
|
|
|
|
|
2003-07-22 00:24:07 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxFTP)
|
2000-12-19 16:56:27 +00:00
|
|
|
DECLARE_PROTOCOL(wxFTP)
|
1998-09-06 18:28:00 +00:00
|
|
|
};
|
|
|
|
|
2001-01-24 16:37:04 +00:00
|
|
|
// the trace mask used by assorted wxLogTrace() in ftp code, do
|
|
|
|
// wxLog::AddTraceMask(FTP_TRACE_MASK) to see them in output
|
|
|
|
#define FTP_TRACE_MASK _T("ftp")
|
|
|
|
|
2001-12-30 22:27:24 +00:00
|
|
|
#endif // wxUSE_PROTOCOL_FTP
|
|
|
|
|
2000-03-15 17:16:35 +00:00
|
|
|
#endif // __WX_FTP_H__
|