Changes the directory on the server to either an absolute or relative path. This also sets the member m_ServerDir which tracks the server directory. The protocol is simple. The client sends a CWD with the supplied argument. The server either returns a 250 if the directory was changed or it returns a 550 if there is no such directory.

Return TypeFunction nameArguments
hzEcodehzFtpClient::SetRemoteDir(hzString&,)

Declared in file: hzFtpClient.h
Defined in file : hzFtpClient.cpp

Function Logic:

0:START 1:rc 2:unknown 3:items 4:Return rc 5:unknown 6:items 7:unknown 8:unknown 9:items rc 10:unknown 11:items len 12:unknown 13:items 14:unknown 15:items 16:unknown 17:unknown 18:rc 19:rc 20:unknown 21:m_ServerDir 22:unknown 23:items 24:m_nTries 25:Return E_OK 26:unknown 27:items 28:Return rc 29:items 30:Return rc

Function body:

hzEcode hzFtpClient::SetRemoteDir (hzString& dir)
{
   //  Changes the directory on the server to either an absolute or relative path. This also sets the member m_ServerDir which tracks the server directory. The
   //  protocol is simple. The client sends a CWD with the supplied argument. The server either returns a 250 if the directory was changed or it returns a 550
   //  if there is no such directory.
   //  
   //  Argument: dir  The taget remote directory
   //  
   //  Returns: E_HOSTFAIL If there was a communication failure and reconnect failed
   //     E_NOTFOUND If the requested directory does not exist on the server or does not permit the client to access it
   //     E_OK  If the remote working directory was set
   _hzfunc("hzFtpClient::SetRemoteDir") ;
   hzString    tgt ;       //  Directory we should end up in
   uint32_t    nRecv ;     //  Length of server response
   uint32_t    len ;       //  Length of client request
   uint32_t    nTry ;      //  Connection retries
   hzEcode     rc ;        //  Return code
   /*
   **  ** Check the directory is reasonable
   **      */
   rc = _checkpath(tgt, m_ServerDir, dir) ;
   if (rc != E_OK)
   {
       threadLog("In dir %s, acting on CD %s results in %s\n", *m_ServerDir, *dir, *tgt) ;
       return rc ;
   }
   if (_hzGlobal_Debug & HZ_DEBUG_CLIENT)
       threadLog("Tgt dir is %s\n", *tgt) ;
   /*
   **  ** Send CWD command and receive resposns, reconnect if required.
   **      */
   for (nTry = 0; nTry < 2; nTry++)
   {
       if (nTry == 1)
       {
           m_ConnControl.Close() ;
           rc = _reconnect() ;
           if (rc != E_OK)
               break ;
       }
       /*
       **  ** Send the CWD command, recv response
       **           */
       sprintf(m_c_sbuf, "CWD %s\r\n", *dir) ;
       len = strlen(m_c_sbuf) ;
       if ((rc = m_ConnControl.Send(m_c_sbuf, len)) != E_OK)
       {
           threadLog("Could not send CWD command - Reconnecting ...\n") ;
           continue ;
       }
       if ((rc = _ftprecv(nRecv, *_fn)) != E_OK)
       {
           threadLog("Could not recv CWD response - Reconnecting ...\n") ;
           continue ;
       }
       break ;
   }
   if (rc == E_OK)
   {
       /*
       **  ** Check respons is valid
       **           */
       if (m_nRescode == 250)
           rc = E_OK ;
       else
           rc = E_NOTFOUND ;
   }
   if (rc == E_OK)
   {
       m_ServerDir = tgt ;
       if (_hzGlobal_Debug & HZ_DEBUG_CLIENT)
           threadLog("Remote dir is now %s\n", *m_ServerDir) ;
       m_nTries = 0;
       return E_OK ;
   }
   if (rc == E_NOTFOUND)
   {
       threadLog("Could not CD to %s (%s)\n", *tgt, m_c_rbuf) ;
       return rc ;
   }
   threadLog("Failure report (err=%s)\n", Err2Txt(rc)) ;
   return rc ;
}