1998-09-06 14:28:00 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2011-03-19 20:14:35 -04:00
|
|
|
// Name: wx/protocol/ftp.h
|
1998-09-06 14:28:00 -04:00
|
|
|
// Purpose: FTP protocol
|
|
|
|
// Author: Vadim Zeitlin
|
2009-01-16 08:34:44 -05:00
|
|
|
// Modified by: Mark Johnson, wxWindows@mj10777.de
|
2004-05-23 10:56:36 -04:00
|
|
|
// 20000917 : RmDir, GetLastResult, GetList
|
1998-09-06 14:28:00 -04:00
|
|
|
// Created: 07/07/1997
|
|
|
|
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-09-06 14:28:00 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2000-03-15 12:16:35 -05:00
|
|
|
|
1998-09-06 14:28:00 -04:00
|
|
|
#ifndef __WX_FTP_H__
|
|
|
|
#define __WX_FTP_H__
|
|
|
|
|
2001-12-30 17:27:24 -05:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_PROTOCOL_FTP
|
|
|
|
|
1998-09-06 14:28:00 -04:00
|
|
|
#include "wx/sckaddr.h"
|
|
|
|
#include "wx/protocol/protocol.h"
|
|
|
|
#include "wx/url.h"
|
|
|
|
|
2003-07-27 18:41:06 -04:00
|
|
|
class WXDLLIMPEXP_NET wxFTP : public wxProtocol
|
2000-03-15 12:16:35 -05:00
|
|
|
{
|
1998-09-06 14:28:00 -04:00
|
|
|
public:
|
2000-12-19 11:56:27 -05:00
|
|
|
enum TransferMode
|
|
|
|
{
|
2001-01-24 11:37:04 -05:00
|
|
|
NONE, // not set by user explicitly
|
2000-12-19 11:56:27 -05:00
|
|
|
ASCII,
|
|
|
|
BINARY
|
|
|
|
};
|
|
|
|
|
|
|
|
wxFTP();
|
|
|
|
virtual ~wxFTP();
|
|
|
|
|
|
|
|
// Connecting and disconnecting
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool Connect(const wxSockAddress& addr, bool wait = true) wxOVERRIDE;
|
|
|
|
virtual bool Connect(const wxString& host) wxOVERRIDE { return Connect(host, 0); }
|
2010-06-17 18:30:31 -04:00
|
|
|
virtual bool Connect(const wxString& host, unsigned short port);
|
2000-12-19 11:56:27 -05:00
|
|
|
|
|
|
|
// disconnect
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool Close() wxOVERRIDE;
|
2000-12-19 11:56:27 -05:00
|
|
|
|
|
|
|
// Parameters set up
|
|
|
|
|
|
|
|
// set transfer mode now
|
2007-04-14 05:58:37 -04:00
|
|
|
void SetPassive(bool pasv) { m_bPassive = pasv; }
|
2000-12-19 11:56:27 -05:00
|
|
|
bool SetBinary() { return SetTransferMode(BINARY); }
|
|
|
|
bool SetAscii() { return SetTransferMode(ASCII); }
|
|
|
|
bool SetTransferMode(TransferMode mode);
|
|
|
|
|
|
|
|
// Generic FTP interface
|
|
|
|
|
2009-01-16 10:08:13 -05:00
|
|
|
// FTP doesn't know the MIME type of the last downloaded/uploaded file
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxString GetContentType() const wxOVERRIDE { return wxEmptyString; }
|
2000-12-19 11:56:27 -05:00
|
|
|
|
|
|
|
// the last FTP server reply
|
2009-01-16 10:08:13 -05:00
|
|
|
const wxString& GetLastResult() const { return m_lastResult; }
|
2000-12-19 11:56:27 -05:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
2009-01-16 10:08:13 -05:00
|
|
|
// SendCommand() does updates m_lastError
|
2000-12-19 11:56:27 -05:00
|
|
|
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 08:24:51 -04:00
|
|
|
// Get the size of a file in the current dir.
|
|
|
|
// this function tries its best to deliver the size in bytes using BINARY
|
2009-01-16 08:34:44 -05:00
|
|
|
// (the SIZE command reports different sizes depending on whether
|
2001-04-22 08:24:51 -04:00
|
|
|
// type is set to ASCII or BINARY)
|
2011-03-22 10:17:38 -04:00
|
|
|
// returns -1 if file is non-existent or size could not be found
|
2001-04-22 08:24:51 -04:00
|
|
|
int GetFileSize(const wxString& fileName);
|
2001-01-24 11:37:04 -05:00
|
|
|
|
|
|
|
// Check to see if a file exists in the current dir
|
2001-04-22 08:24:51 -04:00
|
|
|
bool FileExists(const wxString& fileName);
|
2001-01-24 11:37:04 -05:00
|
|
|
|
2000-12-19 11:56:27 -05:00
|
|
|
// Download methods
|
2014-03-29 20:02:23 -04:00
|
|
|
bool Abort() wxOVERRIDE;
|
2000-12-19 11:56:27 -05:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxInputStream *GetInputStream(const wxString& path) wxOVERRIDE;
|
2000-12-19 11:56:27 -05:00
|
|
|
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 10:24:49 -04:00
|
|
|
return GetList(files, wildcard, false);
|
2000-12-19 11:56:27 -05: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 10:24:49 -04:00
|
|
|
return GetList(files, wildcard, true);
|
2000-12-19 11:56:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// equivalent to either GetFilesList() (default) or GetDirList()
|
|
|
|
bool GetList(wxArrayString& files,
|
|
|
|
const wxString& wildcard = wxEmptyString,
|
2004-09-18 10:24:49 -04:00
|
|
|
bool details = false);
|
2000-12-19 11:56:27 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// this executes a simple ftp command with the given argument and returns
|
2004-09-18 10:24:49 -04:00
|
|
|
// true if it its return code starts with '2'
|
2000-12-19 11:56:27 -05:00
|
|
|
bool DoSimpleCommand(const wxChar *command,
|
|
|
|
const wxString& arg = wxEmptyString);
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2000-12-19 11:56:27 -05:00
|
|
|
// get the server reply, return the first character of the reply code,
|
2005-05-31 05:20:43 -04:00
|
|
|
// '1'..'5' for normal FTP replies, 0 (*not* '0') if an error occurred
|
2000-12-19 11:56:27 -05:00
|
|
|
char GetResult();
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2000-12-19 11:56:27 -05:00
|
|
|
// check that the result is equal to expected value
|
|
|
|
bool CheckResult(char ch) { return GetResult() == ch; }
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2004-09-18 10:24:49 -04: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 17:43:15 -04:00
|
|
|
wxString GetPortCmdArgument(const wxIPV4address& Local, const wxIPV4address& New);
|
2004-09-18 10:24:49 -04:00
|
|
|
|
|
|
|
// accept connection from server in active mode, returns the same socket as
|
2011-04-03 16:31:32 -04:00
|
|
|
// passed in passive mode
|
2004-09-18 10:24:49 -04:00
|
|
|
wxSocketBase *AcceptIfActive(wxSocketBase *sock);
|
|
|
|
|
2000-03-15 12:16:35 -05:00
|
|
|
|
2009-01-16 10:08:13 -05:00
|
|
|
// internal variables:
|
2000-03-15 12:16:35 -05:00
|
|
|
|
2009-01-16 10:08:13 -05:00
|
|
|
wxString m_lastResult;
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2000-12-19 11:56:27 -05:00
|
|
|
// true if there is an FTP transfer going on
|
2009-01-16 10:08:13 -05:00
|
|
|
bool m_streaming;
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2001-01-24 11:37:04 -05:00
|
|
|
// although this should be set to ASCII by default according to STD9,
|
|
|
|
// we will use BINARY transfer mode by default for backwards compatibility
|
2009-01-16 10:08:13 -05:00
|
|
|
TransferMode m_currentTransfermode;
|
2000-03-15 12:16:35 -05:00
|
|
|
|
2004-09-18 10:24:49 -04:00
|
|
|
bool m_bPassive;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
2009-01-16 10:08:13 -05:00
|
|
|
friend class wxInputFTPStream;
|
|
|
|
friend class wxOutputFTPStream;
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxFTP);
|
2000-12-19 11:56:27 -05:00
|
|
|
DECLARE_PROTOCOL(wxFTP)
|
1998-09-06 14:28:00 -04:00
|
|
|
};
|
|
|
|
|
2001-01-24 11:37:04 -05:00
|
|
|
// the trace mask used by assorted wxLogTrace() in ftp code, do
|
|
|
|
// wxLog::AddTraceMask(FTP_TRACE_MASK) to see them in output
|
2009-07-23 16:30:22 -04:00
|
|
|
#define FTP_TRACE_MASK wxT("ftp")
|
2001-01-24 11:37:04 -05:00
|
|
|
|
2001-12-30 17:27:24 -05:00
|
|
|
#endif // wxUSE_PROTOCOL_FTP
|
|
|
|
|
2000-03-15 12:16:35 -05:00
|
|
|
#endif // __WX_FTP_H__
|