| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzFtpClient::GetDirList | (hzVect<hzDirent>&,const hzString&,) |
Declared in file: hzFtpClient.h
Defined in file : hzFtpClient.cpp
Function Logic:
Function body:
hzEcode hzFtpClient::GetDirList (hzVect<hzDirent>& listing, const hzString& Criteria)
{
_hzfunc("hzFtpClient::GetDirList") ;
hzTcpClient X ;
hzDirent meta ;
hzChain Listing ;
hzChain::Iter z ;
hzString filename ;
uint32_t nRecv ;
uint32_t nTotal ;
uint32_t len ;
uint32_t nTry ;
uint32_t nTryData ;
char* j ;
char cvLine [300];
hzEcode rc = E_OK ;
/*
** ** Loop round until success
** */
for (nTry = 0; nTry < 2; nTry++)
{
if (nTry == 1)
{
X.Close() ;
m_ConnControl.Close() ;
rc = _reconnect() ;
if (rc != E_OK)
break ;
}
rc = _openpasv(X) ;
if (rc != E_OK)
{
threadLog("Failed PASV .. aborting\n") ;
continue ;
}
if (Criteria)
sprintf(m_c_sbuf, "LIST %s\r\n", *Criteria) ;
else
sprintf(m_c_sbuf, "LIST\r\n") ;
len = strlen(m_c_sbuf) ;
if ((rc = m_ConnControl.Send(m_c_sbuf, len)) != E_OK)
{
threadLog("Could not send LIST command\n") ;
continue ;
}
if ((rc = _ftprecv(nRecv, *_fn)) != E_OK)
{
threadLog("Did not recieve a response to LIST command\n") ;
continue ;
}
if (m_nRescode != 150)
{
threadLog("Expected code of 150 but got %d. Aborting\n", m_nRescode) ;
_logrescode() ;
rc = E_PROTOCOL ;
break ;
}
nTotal = 0;
Listing.Clear() ;
for (nTryData = 0; nTryData < 3;)
{
rc = X.Recv(m_x_rbuf, nRecv, HZ_MAXPACKET) ;
if (rc != E_OK)
{
threadLog("LIST: Read failed (total so far %d bytes)\n", nTotal) ;
break ;
}
if (!nRecv)
break ;
nTotal += nRecv ;
m_x_rbuf[nRecv] = 0;
Listing << m_x_rbuf ;
}
X.Close() ;
if (rc == E_TIMEOUT || nTryData == 3)
continue ;
if (rc == E_RECVFAIL)
continue ;
if (Listing.Size())
threadLog("LIST: Total listing %d bytes\n", nTotal) ;
else
threadLog("LIST: Empty list. No files\n") ;
if ((rc = _ftprecv(nRecv, *_fn)) != E_OK)
{
threadLog("Did not recieve a response to LIST command\n") ;
continue ;
}
if (m_nRescode != 226)
{
threadLog("LIST: Expected code of 226 (Xfer complete) but got %d. Aborting\n", m_nRescode) ;
rc = E_PROTOCOL ;
}
break ;
}
if (rc == E_OK)
{
if (!Listing.Size())
return rc ;
j = cvLine ;
for (z = Listing ; !z.eof() ; z++)
{
if (*z == CHAR_CR)
continue ;
if (*z == CHAR_NL)
{
*j = 0;
j = cvLine ;
rc = _setmetafile(meta, cvLine) ;
if (rc != E_OK)
break ;
rc = listing.Add(meta) ;
if (rc != E_OK)
break ;
continue ;
}
*j++ = *z ;
}
m_nTries = 0;
return rc ;
}
threadLog("Could not get directory listing\n\n") ;
return rc ;
}