+ wxString code;
+
+ // we handle multiline replies here according to RFC 959: it says that a
+ // reply may either be on 1 line of the form "xyz ..." or on several lines
+ // in whuch case it looks like
+ // xyz-...
+ // ...
+ // xyz ...
+ // and the intermeidate lines may start with xyz or not
+ bool badReply = FALSE;
+ bool firstLine = TRUE;
+ bool endOfReply = FALSE;
+ while ( !endOfReply && !badReply )
+ {
+ m_lastError = ReadLine(m_lastResult);
+ if ( m_lastError )
+ return FALSE;
+
+ // unless this is an intermediate line of a multiline reply, it must
+ // contain the code in the beginning and '-' or ' ' following it
+ if ( m_lastResult.Len() < LEN_CODE + 1 )
+ {
+ if ( firstLine )
+ {
+ badReply = TRUE;
+ }
+ else
+ {
+ wxLogTrace(_T("ftp"), _T("<== %s %s"),
+ code.c_str(), m_lastResult.c_str());
+ }
+ }
+ else // line has at least 4 chars
+ {
+ // this is the char which tells us what we're dealing with
+ wxChar chMarker = m_lastResult.GetChar(LEN_CODE);
+
+ if ( firstLine )
+ {
+ code = wxString(m_lastResult, LEN_CODE);
+ wxLogTrace(_T("ftp"), _T("<== %s %s"),
+ code.c_str(), m_lastResult.c_str() + LEN_CODE + 1);
+
+ switch ( chMarker )
+ {
+ case _T(' '):
+ endOfReply = TRUE;
+ break;
+
+ case _T('-'):
+ firstLine = FALSE;
+ break;
+
+ default:
+ // unexpected
+ badReply = TRUE;
+ }
+ }
+ else // subsequent line of multiline reply
+ {
+ if ( wxStrncmp(m_lastResult, code, LEN_CODE) == 0 )
+ {
+ if ( chMarker == _T(' ') )
+ {
+ endOfReply = TRUE;
+ }
+
+ wxLogTrace(_T("ftp"), _T("<== %s %s"),
+ code.c_str(), m_lastResult.c_str() + LEN_CODE + 1);
+ }
+ else
+ {
+ // just part of reply
+ wxLogTrace(_T("ftp"), _T("<== %s %s"),
+ code.c_str(), m_lastResult.c_str());
+ }
+ }
+ }
+ }