CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 1999
    Posts
    1

    How to make an internet connection ?



    How do you actually make a connection to the internet using VC++ 5. Is it with winsock or what ?

  2. #2
    Join Date
    Mar 1999
    Posts
    7

    Re: How to make an internet connection ?



    Here's a sample

    void CFtpDlg::OnGetInstallation()

    {

    GetDlgItem(IDC_GET_INSTALLATION)->EnableWindow(FALSE);

    CWaitCursor mcurhour;

    CString strMsg = _T(""

    TRY

    {

    CFile myFile;

    BOOL bOpen = myFile.Open(LPCTSTR(m_strBinFileList), CFile::modeRead);

    if (bOpen)

    {

    char szData[4096];

    strMsg.Format("Opened File <%s>", m_strBinFileList);

    AddMsg(strMsg);

    CList<CString,CString&> myList;

    memset(szData, 0, sizeof(szData));

    int nRead = myFile.Read(&szData, sizeof(szData));

    if (nRead)

    {

    CString strFile = _T(""

    LPSTR pItem = strtok(szData, "\r\n"

    while (pItem)

    {

    strFile = pItem;

    myList.AddTail(strFile);

    pItem = strtok(NULL, "\r\n"

    }

    }

    myFile.Close();

    if (!myList.IsEmpty())

    {

    CInternetSession mySession = "my session";

    CFtpConnection* pConn = NULL;

    pConn = mySession.GetFtpConnection(LPCTSTR(m_strHost), LPCTSTR(m_strUser), LPCTSTR(m_strPassword));

    if (pConn)

    {

    strMsg.Format("OPENED Connection to server <%s>", m_strHost);

    AddMsg(strMsg);

    CString strDir = _T(""

    if (pConn->GetCurrentDirectory(strDir))

    {

    }

    CString strGetFile = _T(""

    CString strPutFile = _T(""

    CString strFile = _T(""

    while (!myList.IsEmpty())

    {

    strFile = myList.RemoveHead();

    strGetFile.Format("%s/%s", m_strSourceBinDir, strFile);

    strPutFile.Format("%s\\%s", m_strLocalDir, strFile);

    BOOL bGot = pConn->GetFile(strGetFile, strPutFile, FALSE);

    if (!bGot)

    {

    DWORD dwErr = GetLastError();

    TRACE("Unable to Get File <%s> due to error < %lu >\r\n", strGetFile, dwErr);

    }

    else

    {

    strMsg.Format("Retrieved file <%s>", strFile);

    AddMsg(strMsg);

    strMsg.Format("Saved as file <%s>", strPutFile);

    AddMsg(strMsg);

    }

    }

    pConn->Close();

    delete pConn;

    AddMsg("Retrieved COMPLETED"

    strMsg.Format("CLOSED Connection to server <%s>", m_strHost);

    AddMsg(strMsg);

    }

    mySession.Close();

    }

    }

    }

    CATCH( CFileException, e )

    {

    #ifdef _DEBUG

    afxDump << "File could not be opened " << e->m_cause << "\n";

    #endif

    }

    END_CATCH

    GetDlgItem(IDC_GET_INSTALLATION)->EnableWindow(TRUE);

    }



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured