// Created: 07/07/1997
// RCS-ID: $Id$
// Copyright: (c) 1997, 1998 Guilhem Lavaux
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "ftp.h"
#endif
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxFTP, wxProtocol)
-IMPLEMENT_PROTOCOL(wxFTP, wxT("ftp"), wxT("ftp"), TRUE)
+IMPLEMENT_PROTOCOL(wxFTP, wxT("ftp"), wxT("ftp"), true)
// ============================================================================
// implementation
wxFTP::wxFTP()
{
m_lastError = wxPROTO_NOERR;
- m_streaming = FALSE;
+ m_streaming = false;
m_currentTransfermode = NONE;
m_user = wxT("anonymous");
if ( !wxProtocol::Connect(addr) )
{
m_lastError = wxPROTO_NETERR;
- return FALSE;
+ return false;
}
if ( !m_user )
{
m_lastError = wxPROTO_CONNERR;
- return FALSE;
+ return false;
}
// we should have 220 welcome message
if ( !CheckResult('2') )
{
Close();
- return FALSE;
+ return false;
}
wxString command;
if ( rc == '2' )
{
// 230 return: user accepted without password
- return TRUE;
+ return true;
}
if ( rc != '3' )
{
Close();
- return FALSE;
+ return false;
}
command.Printf(wxT("PASS %s"), m_passwd.c_str());
if ( !CheckCommand(command, '2') )
{
Close();
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
bool wxFTP::Connect(const wxString& host)
if ( m_streaming )
{
m_lastError = wxPROTO_STREAMING;
- return FALSE;
+ return false;
}
if ( IsConnected() )
// ...
// xyz ...
// and the intermeidate lines may start with xyz or not
- bool badReply = FALSE;
- bool firstLine = TRUE;
- bool endOfReply = FALSE;
+ bool badReply = false;
+ bool firstLine = true;
+ bool endOfReply = false;
while ( !endOfReply && !badReply )
{
wxString line;
{
if ( firstLine )
{
- badReply = TRUE;
+ badReply = true;
}
else
{
switch ( chMarker )
{
case _T(' '):
- endOfReply = TRUE;
+ endOfReply = true;
break;
case _T('-'):
- firstLine = FALSE;
+ firstLine = false;
break;
default:
// unexpected
- badReply = TRUE;
+ badReply = true;
}
}
else // subsequent line of multiline reply
{
if ( chMarker == _T(' ') )
{
- endOfReply = TRUE;
+ endOfReply = true;
}
wxLogTrace(FTP_TRACE_MASK, _T("<== %s %s"),
if ( transferMode == m_currentTransfermode )
{
// nothing to do
- return TRUE;
+ return true;
}
wxString mode;
wxLogError(_("Failed to set FTP transfer mode to %s."), (const wxChar*)
(transferMode == ASCII ? _("ASCII") : _("binary")));
- return FALSE;
+ return false;
}
// If we get here the operation has been succesfully completed
// Set the status-member
m_currentTransfermode = transferMode;
- return TRUE;
+ return true;
}
bool wxFTP::DoSimpleCommand(const wxChar *command, const wxString& arg)
{
wxLogDebug(_T("FTP command '%s' failed."), fullcmd.c_str());
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
bool wxFTP::ChDir(const wxString& dir)
str = wxT("RNFR ") + src;
if ( !CheckCommand(str, '3') )
- return FALSE;
+ return false;
str = wxT("RNTO ") + dst;
// wait for "226 transfer completed"
m_ftp->CheckResult('2');
- m_ftp->m_streaming = FALSE;
+ m_ftp->m_streaming = false;
}
else
{
// read this reply
m_ftp->CheckResult('2');
- m_ftp->m_streaming = FALSE;
+ m_ftp->m_streaming = false;
}
else
{
wxSscanf(straddr, wxT("%d,%d,%d,%d,%d,%d"),
&a[2],&a[3],&a[4],&a[5],&a[0],&a[1]);
- wxUint32 hostaddr = (wxUint16)a[5] << 24 |
- (wxUint16)a[4] << 16 |
- (wxUint16)a[3] << 8 |
- a[2];
+ wxUint32 hostaddr = (wxUint16)a[2] << 24 |
+ (wxUint16)a[3] << 16 |
+ (wxUint16)a[4] << 8 |
+ a[5];
wxUint16 port = (wxUint16)a[0] << 8 | a[1];
wxIPV4address addr;
return NULL;
}
- client->Notify(FALSE);
+ client->Notify(false);
return client;
}
bool wxFTP::Abort()
{
if ( !m_streaming )
- return TRUE;
+ return true;
- m_streaming = FALSE;
+ m_streaming = false;
if ( !CheckCommand(wxT("ABOR"), '4') )
- return FALSE;
+ return false;
return CheckResult('2');
}
if ( !CheckCommand(tmp_str, '1') )
return NULL;
- m_streaming = TRUE;
+ m_streaming = true;
in_stream = new wxInputFTPStream(this, sock);
if ( !CheckCommand(tmp_str, '1') )
return NULL;
- m_streaming = TRUE;
+ m_streaming = true;
return new wxOutputFTPStream(this, sock);
}
{
wxSocketBase *sock = GetPort();
if (!sock)
- return FALSE;
+ return false;
// NLST : List of Filenames (including Directory's !)
// LIST : depending on BS of FTP-Server
// - Windows : like "dir" command
// - others : ?
wxString line(details ? _T("LIST") : _T("NLST"));
- if ( !!wildcard )
+ if ( !wildcard.IsEmpty() )
{
line << _T(' ') << wildcard;
}
if (!CheckCommand(line, '1'))
{
- return FALSE;
+ return false;
}
files.Empty();
while ( ReadLine(sock, line) == wxPROTO_NOERR )
// the file list should be terminated by "226 Transfer complete""
if ( !CheckResult('2') )
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
bool wxFTP::FileExists(const wxString& fileName)
// current dir. It does so by simply doing an NLST (via GetList).
// If this succeeds (and the list is not empty) the file exists.
- bool retval = FALSE;
+ bool retval = false;
wxArrayString fileList;
- if ( GetList(fileList, fileName, FALSE) )
+ if ( GetList(fileList, fileName, false) )
{
// Some ftp-servers (Ipswitch WS_FTP Server 1.0.5 does this)
// displays this behaviour when queried on a non-existing file:
&statuscode, &filesize) == 2 )
{
// We've gotten a good reply.
- ok = TRUE;
+ ok = true;
}
else
{
// Something bad happened.. A "2yz" reply with no size
// Fallback
- ok = FALSE;
+ ok = false;
}
}
SetTransferMode(oldTransfermode);
}
- if ( !ok ) // this is not a direct else clause.. The size command might return an invalid "2yz" reply
+ // this is not a direct else clause.. The size command might return an
+ // invalid "2yz" reply
+ if ( !ok )
{
// The server didn't understand the "SIZE"-command or it
// returned an invalid reply.
// We now try to get details for the file with a "LIST"-command
// and then parse the output from there..
wxArrayString fileList;
- if ( GetList(fileList, fileName, TRUE) )
+ if ( GetList(fileList, fileName, true) )
{
if ( !fileList.IsEmpty() )
{
// substring containing the name we are looking for. We
// stop the iteration at the first occurrence of the
// filename. The search is not case-sensitive.
- bool foundIt = FALSE;
+ bool foundIt = false;
size_t i;
for ( i = 0; !foundIt && i < fileList.Count(); i++ )
if ( wxSscanf(fileList[i].c_str(),
_T("%*s %*s %*s %*s %i %*s %*s %*s %*s"),
- &filesize) == 9 )
- {
- // We've gotten a good response
- ok = TRUE;
- }
- else
+ &filesize) != 9 )
{
// Hmm... Invalid response
wxLogTrace(FTP_TRACE_MASK,
{
if ( wxSscanf(fileList[i].c_str(),
_T("%*s %*s %i %*s"),
- &filesize) == 4 )
- {
- // valid response
- ok = TRUE;
- }
- else
+ &filesize) != 4 )
{
// something bad happened..?
wxLogTrace(FTP_TRACE_MASK,
return filesize;
}
-
-#if WXWIN_COMPATIBILITY_2
-// deprecated
-wxList *wxFTP::GetList(const wxString& wildcard, bool details)
-{
- wxSocketBase *sock = GetPort();
- if (!sock)
- return NULL;
- wxList *file_list = new wxList;
- wxString line;
- // NLST : List of Filenames (including Directory's !)
- // LIST : depending on BS of FTP-Server
- // - Unix : result like "ls" command
- // - Windows : like "dir" command
- // - others : ?
- if (!details)
- line = _T("NLST"); // Default
- else
- line = _T("LIST");
- if (!wildcard.IsNull())
- line += wildcard;
- if (!CheckCommand(line, '1'))
- {
- delete sock;
- delete file_list;
- return NULL;
- }
- while (GetLine(sock, line) == wxPROTO_NOERR)
- {
- file_list->Append((wxObject *)(new wxString(line)));
- }
- if (!CheckResult('2'))
- {
- delete sock;
- file_list->DeleteContents(TRUE);
- delete file_list;
- return NULL;
- }
- return file_list;
-}
-#endif // WXWIN_COMPATIBILITY_2
-
#endif // wxUSE_PROTOCOL_FTP