?
Solved

MFC Progress bar for status of FTP upload

Posted on 2005-03-16
17
Medium Priority
?
689 Views
Last Modified: 2013-11-20
I have code in place to upload a file with ftp and I want to advance a progress bar to show the status of the upload.
I have added a progress Control to my dialog and associated a CProgressCtrl member variable with it.

The code is as follows:

HINTERNET m_hInetHandle = InternetOpen ( "FTP Backup", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );

HINTERNET m_hFtpHandle = InternetConnectA (m_hInetHandle, (LPCSTR) szUrl, INTERNET_DEFAULT_FTP_PORT, (LPCSTR) szUser, (LPCSTR) szPW, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0) ;

int rv = FtpPutFileA ( m_hFtpHandle, (LPCSTR) szSource, (LPCSTR) szDest, FTP_TRANSFER_TYPE_UNKNOWN, 0 );


if ( m_hFtpHandle )
          InternetCloseHandle ( m_hFtpHandle ) ;
if ( m_hInetHandle )
          InternetCloseHandle ( m_hInetHandle ) ;

The name of the progCtrl is  m_Progress.

Thanks

PT
0
Comment
Question by:ptrennum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
17 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 13558239
Check out http://support.microsoft.com/default.aspx?scid=kb;en-us;234913 ("How To Provide Download/Upload Progress Information when Using WinInet"). All you have to do is replacing 'cout' in the sample with calls to 'CProgressCtrl::SetStep()'.
0
 

Author Comment

by:ptrennum
ID: 13558350
I was hoping for some info a little more  specific to my case.

Thanks

PT
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ptrennum
ID: 13558392
Just out of curriosity jkr you never worked at a company called Keigan Systems did you?  I ask becasue I worked with a really clever software engineer whom had the same initials?
0
 
LVL 86

Expert Comment

by:jkr
ID: 13558404
Well, using 'INTERNET_STATUS_RESPONSE_RECEIVED' and evaluating the number of bytes received in

DWORD dwBytes = *(LPDWORD*)lpvStatusInformation;

would work the same way, indeed. I haven't used it though, since it's mainly intended for asynchronous transfer.
0
 
LVL 86

Expert Comment

by:jkr
ID: 13558408
Nope, never heard of that company...
0
 

Author Comment

by:ptrennum
ID: 13558483
Is there anyway I could get a more specific response to this question I am getting confused with the call backs etc.

PT
0
 

Author Comment

by:ptrennum
ID: 13559206
I guess this is a little trickier then I thought origianlly.  If anyone has some good infomration about this it will be reatly appreciated.

Thanks,

PT
0
 

Author Comment

by:ptrennum
ID: 13565542
Ok,

I've been looking through the sample code at http://support.microsoft.com/default.aspx?scid=kb;en-us;234913 
It seems that it is all based on HTTP, I am using FTP to do just an upload.  Are there functions similar to HttpQueryInfo() but designed to work with the FTP protocol?

PT
0
 

Author Comment

by:ptrennum
ID: 13568403
After reading the entire article located at http://support.microsoft.com/default.aspx?scid=kb;en-us;234913 
I noticed on nearly the last line that:

If you are attempting to upload or download from an FTP resource, you will not be able to use FtpPutFile or FtpGetFile and expect to determine progress information. You should use FtpOpenFile and then use InternetReadFile and InternetWriteFile as described above.

Well this is exactly what I was trying to do and I believe was pretty clearly stated in my original question.  I am surprised that no one mentioned to me that it wouldn't work with the way I had originally programmed it especially when I included my own source code.
0
 
LVL 86

Expert Comment

by:jkr
ID: 13568455
Sorry, I thought you read the article to the end :o)

That's why I wrote "All you have to do is replacing 'cout' in the sample with calls to 'CProgressCtrl::SetStep()'"
0
 

Author Comment

by:ptrennum
ID: 13575209
The thing is that FtpOpenFIle and InternetWriteFile are vastly different then using FtpPutFile which is used in my code example, Some help on how to use those new functions correctly woulda been and still would be greatly appreciated.

PT
0
 

Author Comment

by:ptrennum
ID: 13576337
There was actually quite a bit more to do then replacing the cout calls.

In case someone out there is interested in the solution I will post the code that I have written:

HANDLE FH=CreateFile(pLocalFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
      if (FH == INVALID_HANDLE_VALUE)
            return FALSE;

      DWORD filesize=GetFileSize(FH, NULL);
      DWORD range=filesize/1024;
      if ((filesize%1024) != 0)
            range++;
      pProgressObj->SetRange(0, range);

      HINTERNET ftpFH=FtpOpenFileA(hInet, pRemoteFilePath, GENERIC_WRITE, FTP_TRANSFER_TYPE_UNKNOWN, NULL);

      BYTE Buffer[1024];
      DWORD nBytes, Pos=0;

      while(ReadFile(FH, Buffer, 1024, &nBytes, NULL) != 0 && nBytes != 0)
      {
            DWORD sentBytes=0, ftpdBytes;
            while(sentBytes != nBytes && InternetWriteFile(ftpFH, Buffer, nBytes-sentBytes, &ftpdBytes) != FALSE)
                  sentBytes+=ftpdBytes;
            pProgressObj->SetPos(++Pos);
      }

      InternetCloseHandle(ftpFH);
      CloseHandle(FH);

I hope that this is usefull to people trying to do a similar task.  

Thanks JKR for the link but I'm not quite sure about the points on this one.  

Part of the reason I pay for this service is so I can learn from the experts advice and knowledge but if they aren't willing to communicate then it takes much longer and is much more difficult to get the information I need.  Maybe there should be better incentives for the experts so that we can get more specific results - we do ask specific questions.

PT
0
 
LVL 86

Expert Comment

by:jkr
ID: 13576382
Sorry, I was just about to assemble a sample - but, I do have real work to do also... And I prefer not to comment if I don't have anything new to contribute.
0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16368712
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question