tags:

views:

44

answers:

3
void GetFtpFile(LPCTSTR pszServerName, LPCTSTR pszRemoteFile, LPCTSTR pszLocalFile)
{
   CInternetSession session(_T("My FTP Session"));
   CFtpConnection* pConn = NULL;

   pConn = session.GetFtpConnection(pszServerName);
   //get the file
   if (!pConn->GetFile(pszRemoteFile, pszLocalFile))
   {
      //display an error
   }
   delete pConn;
   session.Close();
}

How do I get specific error information from GetFile()?

Thank You.

+1  A: 

What about GetLastError()?

John at CashCommons
+1  A: 

According to the MSDN it's GetLastError()

RickNotFred
+1  A: 

According to MSDN:

Return Value

Nonzero if successful;

otherwise 0. If the call fails, the Win32 function GetLastError may be called to determine the cause of the error.

GetLastError() returns an error code, but you can call FormatMessage() to get a human-readable string from the error code. Here's a utility function that does that for you:

std::string formatwinerr(unsigned long errCode)
{
    LPVOID lpMsgBuf;

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM ,
        0,
        errCode,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );

    std::string ret((const char*)lpMsgBuf);

    LocalFree(lpMsgBuf);

    return ret;
}
John Dibling
thanks...........
Tommy
You're welcome.
John Dibling
FYI - And for winInet messages a specific module must be specified: http://stackoverflow.com/questions/2159458/not-sure-why-formatmessage-is-returning-a-blank-string
Tommy