CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: ftp file size

  1. #1
    Join Date
    Jun 2013
    Posts
    21

    ftp file size

    My question is...can this be fixed to work right??????????????????


    Code:
    int index;
             CString strText;
             index = m_dir.GetCurSel();
    
             m_dir.GetText(index,strText);
            
    
    	
    		 HINTERNET handle1 = FtpOpenFile(hIConnect,strText,GENERIC_READ,FTP_TRANSFER_TYPE_BINARY,0);
    		DWORD filesized =  FtpGetFileSize(handle1,NULL);
    		CString csNumber;
    csNumber.Format("%lu", filesized);
    
    MessageBox(csNumber,csNumber,MB_OK);
    HANDLE hFile    = CreateFile(strText, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    char Buffer[4024];
      DWORD dwRead =0;
     
      
    
    
    m_yay.SetRange(0,filesized);
      while(InternetReadFile(handle1, Buffer, sizeof(Buffer), &dwRead) == TRUE)
      {
        if ( dwRead == 0) 
          break;
        DWORD dwWrite = 0;
    	progress2 += dwRead;
    
    	m_yay.SetPos(progress2);
        WriteFile(hFile, Buffer, dwRead, &dwWrite, NULL);
      }
    that code above is for a FTP CLIENT using WININET. the code is getting a file from the server and downloading...it works, but the progress bar is not working right....like it fills to fast...sometimes it doesn't even move...so can you help me with this problem
    Last edited by vaas; July 3rd, 2013 at 11:25 PM.

  2. #2
    Join Date
    Jun 2013
    Posts
    21

    Re: ftp file size

    MY question is....why does the progress bar go crazy..filling like 10000 times..instead of starting from the beginning and slowing incrementing ot the end....

    I used StepIt instead of setpos and its almost working...
    [code]


    the progress bar goes crazy..it goes all the way about 1 million times....
    Last edited by vaas; July 4th, 2013 at 12:49 AM.

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: ftp file size

    m_yay.SetRange(0,filesized);
    Please read carefully about PBM_SETRANGE message
    Best regards,
    Igor

  4. #4
    Join Date
    Jun 2013
    Posts
    21

    Re: ftp file size

    alright.. I fixed
    Code:
     m_yay.SetRange(0,100);
    And also..here isi the code that I edited..but still the progress is going crazy. Should I put the "StepIt" function in a while loop? Or maybe chop it up and put it in a FOR LOOP?
    Code:
    while(InternetReadFile(handle1, Buffer, sizeof(Buffer), &dwRead) == TRUE)
      {
        if ( dwRead == 0) 
        break;
        DWORD dwWrite = 0;
        WriteFile(hFile, Buffer, dwRead, &dwWrite, NULL);
    	m_yay.StepIt();
      }

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: ftp file size

    Quote Originally Posted by vaas View Post
    alright.. I fixed
    Code:
     m_yay.SetRange(0,100);
    What did you fixed?

    Quote Originally Posted by vaas View Post
    And also..here isi the code that I edited..but still the progress is going crazy. Should I put the "StepIt" function in a while loop? Or maybe chop it up and put it in a FOR LOOP?
    Code:
    while(InternetReadFile(handle1, Buffer, sizeof(Buffer), &dwRead) == TRUE)
      {
        if ( dwRead == 0) 
        break;
        DWORD dwWrite = 0;
        WriteFile(hFile, Buffer, dwRead, &dwWrite, NULL);
    	m_yay.StepIt();
      }
    Why do you use StepIt()? Did you call SetStep() before?

    Perhaps, you'll get back to reading MSDN documentation about CProgressCtrl and its methods?
    Victor Nijegorodov

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: ftp file size

    Well, probably it must be something like:
    Code:
      while(InternetReadFile(handle1, Buffer, sizeof(Buffer), &dwRead) == TRUE)
      {
        if ( dwRead == 0) 
          break;
        DWORD dwWrite = 0;
        progress2 += dwRead;
    
        UINT progressPercent = DOUBLE(progress2) * 100 / filesized + 0.5;
    
        m_yay.SetPos(progressPercent);
        WriteFile(hFile, Buffer, dwRead, &dwWrite, NULL);
      }
    Best regards,
    Igor

  7. #7
    Join Date
    Nov 2012
    Posts
    21

    Re: ftp file size

    Cool..i got it work with Igor Vartanov code
    here is the code
    Code:
    void CSimpleftpclientDlg::OnButton4() 
    {
    
    
    int index;
             CString strText;
             index = m_dir.GetCurSel();
    
             m_dir.GetText(index,strText);
            
    
    	
    		 HINTERNET handle1 = FtpOpenFile(hIConnect,strText,GENERIC_READ,FTP_TRANSFER_TYPE_BINARY,0);
    		DWORD filesized =  FtpGetFileSize(handle1,NULL);
    		CString csNumber;
    csNumber.Format("%lu", filesized);
    GetDlgItem(IDC_EDIT4)->SetWindowText(csNumber);
    
    HANDLE hFile    = CreateFile(strText, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    char Buffer[4024];
      DWORD dwRead =0;
     
      
    
    
    m_yay.SetRange(0,100);
      while(InternetReadFile(handle1, Buffer, sizeof(Buffer), &dwRead) == TRUE)
      {
        if ( dwRead == 0) 
          break;
        DWORD dwWrite = 0;
    	progress2 += dwRead;
    	UpdateData(true);
    	CString what = m_what;
    	UpdateData(false);
    	DWORD dwNO;
    
    dwNO= atol((char*)(LPCTSTR)what);
    	UINT progressPercent = DOUBLE(progress2) * 100 / dwNO;
    
        m_yay.SetPos(progressPercent);
    
        WriteFile(hFile, Buffer, dwRead, &dwWrite, NULL);
      }
    
    
    
    
    
    }
    thx
    Last edited by terryeverlast; July 5th, 2013 at 04:17 PM. Reason: messed up

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