• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 706
  • Last Modified:

MFC Progress bar for status of FTP upload

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
ptrennum
Asked:
ptrennum
  • 9
  • 5
1 Solution
 
jkrCommented:
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
 
ptrennumAuthor Commented:
0
 
ptrennumAuthor Commented:
I was hoping for some info a little more  specific to my case.

Thanks

PT
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ptrennumAuthor Commented:
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
 
jkrCommented:
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
 
jkrCommented:
Nope, never heard of that company...
0
 
ptrennumAuthor Commented:
Is there anyway I could get a more specific response to this question I am getting confused with the call backs etc.

PT
0
 
ptrennumAuthor Commented:
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
 
ptrennumAuthor Commented:
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
 
ptrennumAuthor Commented:
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
 
jkrCommented:
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
 
ptrennumAuthor Commented:
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
 
ptrennumAuthor Commented:
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
 
jkrCommented:
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
 
GranModCommented:
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now