Click here to Skip to main content
Licence 
First Posted 2 Dec 2004
Views 29,027
Bookmarked 17 times

Download files from internet

By | 2 Dec 2004 | Article
Download the files from internet

Introduction

This application used to download the file from internet by giving the path.
#include <afxinet.h> <AFXINET.H>
CInternetSession netSession; 
CInternetSession having the member function OpenURL() to open the URL.
    CStdioFile *fTargetFile;    
    fTargetFile=netSession.OpenURL(str,1,INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_RELOAD);
This application displays the download rate and show how much percent downloaded in progress bar.
    int filesize=fTargetFile->SeekToEnd();
         int outfs;
    outfs=filesize/1024;
CProgressCtrl *prg=(CProgressCtrl*)GetDlgItem(IDC_PRG1);
    COleDateTime StartTime=COleDateTime::GetCurrentTime();
    prg->SetRange32(0,filesize);
        int bytesread=0,pos=0;
    char strbuf[512];
       CString szDestPath;
    GetDlgItemText(IDC_EDIT2,szDestPath);
    szDestPath+="\\";
    szDestPath+=fTargetFile->GetFileName();
    CFile fDestFile(szDestPath,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
    while(bytesread=fTargetFile->Read(strbuf,512))
    {
        pos+=bytesread;
        prg->SetPos(pos);            
        
        float percent=(float)pos/(float)filesize;
        int p=percent*100;
        fDestFile.Write(strbuf,bytesread);
        COleDateTimeSpan dlTimeElapsed=COleDateTime::GetCurrentTime()-StartTime;
        secs=dlTimeElapsed.GetTotalSeconds();

        int kb=pos/1024;
        kbpsecs=kb/secs;
        CString Kbps,szPercent;
        Kbps.Format("%0.1f KB/Sec",kbpsecs);
        SetDlgItemText(IDC_STATIC1,Kbps);
        
        szPercent.Format("%d %%",p);
        SetDlgItemText(IDC_STATIC4,szPercent);
        Sleep(100);
    }
This code used to download the files from internet by giving the path.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Eswar_Illuri

Web Developer

India India

Member

I am working at Virinchi Technologies as programmer in vc++,COM & symbian c++. My hobbies are painting, and play chess and carams.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questiononly 5 kbps ?why ? Pinmembermircea1313134:35 9 Mar '07  
AnswerRe: only 5 kbps ?why ? [modified] PinmemberABates8523:11 25 Oct '07  
GeneralError in proxy Pinmemberasfur3:33 4 Jan '07  
Generalstatus of connect PinsussKutti Ra16:21 30 Sep '05  
how to find the system weather system connect to internet or not. if yes connected duration

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 3 Dec 2004
Article Copyright 2004 by Eswar_Illuri
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid