Click to See Complete Forum and Search --> : How to make an internet connection ?


Kareem
March 29th, 1999, 01:32 PM
How do you actually make a connection to the internet using VC++ 5. Is it with winsock or what ?

earth
March 29th, 1999, 01:38 PM
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);

}