Rename a file on the server
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzFtpClient::FileRename | (hzString&,hzString&,) |
Declared in file: hzFtpClient.h
Defined in file : hzFtpClient.cpp
Function Logic:
Function body:
hzEcode hzFtpClient::FileRename (hzString& oldsvrname)hzString& newsvrname,
{
// Rename a file on the server
//
// Arguments: 1) oldsvrname Old name of file/directory on server
// 2) newname New name of file/directory on server
//
// Returns: E_HOSTFAIL If there was a communication failure and reconnect failed
// E_WRITEFAIL If the requested server file was not renamed
// E_OK If the remote file was renamed
_hzfunc("hzFtpClient::FileRename") ;
uint32_t nRecv ; // Length of server response
uint32_t len ; // Length of client request
uint32_t nTry ; // Reconnection retry count
hzEcode rc ; // Return code
/*
** ** Send RNFR & RNTO commands 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 RNFR (rename from) command and check the response
** */
// sprintf(m_c_sbuf, "RENAME %s %s\r\n", *oldsvrname, *newsvrname) ;
sprintf(m_c_sbuf, "RNFR %s\r\n", *oldsvrname) ;
len = strlen(m_c_sbuf) ;
if ((rc = m_ConnControl.Send(m_c_sbuf, len)) != E_OK)
{
threadLog("Could not send RNFR command (file %s to %s)\n", *oldsvrname, *newsvrname) ;
continue ;
}
if ((rc = _ftprecv(nRecv, *_fn)) != E_OK)
{
threadLog("Could not get RNFR response (file %s to %s)\n", *oldsvrname, *newsvrname) ;
continue ;
}
if (m_nRescode == 350)
{
/*
** ** The RNFR was OK so now send the RNTO
** */
sprintf(m_c_sbuf, "RNTO %s\r\n", *newsvrname) ;
len = strlen(m_c_sbuf) ;
if ((rc = m_ConnControl.Send(m_c_sbuf, len)) != E_OK)
{
threadLog("Could not send RNTO command (file %s to %s)\n", *oldsvrname, *newsvrname) ;
continue ;
}
if ((rc = _ftprecv(nRecv, *_fn)) != E_OK)
{
threadLog("Could not get RNTO response (file %s to %s)\n", *oldsvrname, *newsvrname) ;
continue ;
}
}
break ;
}
/*
** ** Check server response
** */
if (m_nRescode >&eq; 400)
{
threadLog("Got bad response (%d) to RNFR/RNTO command (file %s to %s)\n", m_nRescode, *oldsvrname, *newsvrname) ;
return E_NODATA ;
}
return E_OK ;
}