Click here to Skip to main content
6,596,602 members and growing! (20,276 online)
Email Password   helpLost your password?
General Programming » Internet / Network » General     Intermediate

Download files from internet

By Eswar_Illuri

Download the files from internet
VC6Win2K, MFC, Dev
Posted:2 Dec 2004
Views:22,625
Bookmarked:13 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
16 votes for this article.
Popularity: 2.49 Rating: 2.06 out of 5
7 votes, 43.8%
1
2 votes, 12.5%
2

3
3 votes, 18.8%
4
4 votes, 25.0%
5

Introduction

This application used to download the file from internet by giving the path.
#include <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


Member
I am working at Virinchi Technologies as programmer in vc++,COM & symbian c++. My hobbies are painting, and play chess and carams.
Occupation: Web Developer
Location: India India

Other popular Internet / Network articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 4 of 4 (Total in Forum: 4) (Refresh)FirstPrevNext
Generalonly 5 kbps ?why ? Pinmembermircea1313135:35 9 Mar '07  
AnswerRe: only 5 kbps ?why ? [modified] PinmemberABates850:11 26 Oct '07  
GeneralError in proxy Pinmemberasfur4:33 4 Jan '07  
Generalstatus of connect PinsussKutti Ra17:21 30 Sep '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 2 Dec 2004
Editor:
Copyright 2004 by Eswar_Illuri
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project