SOLVED - VB6 OnTransferProgress

I was wondering how to use the OnTransferProgress in VB6

What I would like to do is get the current size of the file that is being uploaded and also how much time is left till it's done being uploaded.

Is this possible?

Thanks!

I've tryied this but I get nothing.

Private Function objFTP_OnTransferProgress32(nBytesTransferred As Byte)



    Label1.Caption = nBytesTransferred



End Function

Am I way off here?

OK I figured it out
Just in case there are other newbies out there like me when it comes to dll and not ocx's

Put this in the declarations:
Dim WithEvents objFTP As FTPConnection

then on form load:



Set objFTP = New FTPConnection




You will now have all the functions for objFTP
Private Sub objFTP_OnTransferProgress32(ByVal nBytesTransferred As Long)



Label1.Caption = nBytesTransferred



End Sub

Hope this helps some other people

EDIT:::
One question more question I have, is there any way to estimate the time the file has to upload or download. If there was a TransferSpeed on the OnTransferProgress32 we could just do a little math to figure it out. Unless there is a better way

Regarding the time left.

Before you start the transfer. Save the following values:
- TransferStartTime
- StartPosition in bytes (>0 if you resume)
- FileSize in bytes.

then you can do the following calculation on every OnTransferProgressEvent

Speed = nBytesTransferred / (NowTime - TransferStartTime)
BytesLeft = FileSize - StartPosition - nBytesTransferred
TimeLeft = BytesLeft / Speed

-Mat
SmartFTP

HELP NEW PROBLEM!!!!

If I do this route:

Put this in the declarations:
Dim WithEvents objFTP As FTPConnection

then on form load:



Set objFTP = New FTPConnection




when I run my app in VB everything runs fine. After I compile the exe and I run my app as soon as the smartftp gets called my exe crashes on me. If I comment out the above code and put this back in
Public objFTP As sfFTPLib.FTPConnection
everything is fine but now again I don't have the OnTransferProgressEvent

is this a bug or am I doing something wrong.

If I can get this to work we are going ot make this dll purchase...one of hte best ftp.dll for vb I found!

What version of the dll did you test with?

Does it work with a version you previously tested?

Can you make a small sample applications to reproduce the problem and post the source?

Does it crash when the event is fired or when the FTPConnection object is created? In the first case I think we have the problem described in this article:
http://www.mvps.org/vcfaq/com/1.htm

-Mat

Looks like it happens when the event is fired.
Here is the code. I edited your demo

I get this error with using 1.0.1.20 (first one I started using) till the newest version.

with the the link you sent is this somthing I will have to do on my end or do you need to change something in the dll?

If it's something I need to do I'll have to spend a while trying to figure it out. This still is a little new to me. I'm used to working with ocx and not to many dll's

Thanks for responding so quickly

'Method used in demo



'Public objFTP As sfFTPLib.FTPConnection







'method used by me



'This works inside VB but once compiled to an exe causes a crash



Dim WithEvents objFTP As FTPConnection







Private Sub Form_Load()



'method used by me



'This works inside VB but once compiled to an exe causes a crash



Set objFTP = New FTPConnection











' VB6 binding howto



    ' http://kandkconsulting.tripod.com/VB/Tutorials/vb_binding_tutorial.htm







    'Early Binding "Dual Interface"



    'Note: Force the compiler to use the dual interface if available



    Set objFTP = CreateObject("sfFTPLib.FTPConnection")



    'Early Binding "Mid Level"



    'Note: The compiler may use the dual interface



    'Set objFTP = New sfFTPLib.FTPConnection



    



    objFTP.Host = "ftp.smartftp.com"



    objFTP.Port = 21



    objFTP.Protocol = ftpProtocolNormal



    objFTP.Username = "anonymous"



    objFTP.Password = "test@test.com"



    objFTP.Passive = True



    objFTP.LogFile = "VB6Demo.log"



    



    If objFTP.Connect = sfFTPLib.enumError.ftpErrorSuccess Then



        MsgBox ("Connected.")



        If objFTP.ChangeDirectory("/SmartFTP") = sfFTPLib.enumError.ftpErrorSuccess Then



            MsgBox ("ChangeDirectory() successful.")



            ' Read Directory



            If objFTP.ReadDirectory() = sfFTPLib.enumError.ftpErrorSuccess Then



                MsgBox ("ReadDirectory() successful.")



                Dim objDirectory As sfFTPLib.FTPDirectory



                Set objDirectory = objFTP.Directory



                Dim objItem As sfFTPLib.FTPItem



                Dim strList



                For Each objItem In objDirectory



                    strList = strList & "Type=" & objItem.Type & "; Name=" & objItem.Name & "; Size=" & objItem.Size32 & vbCrLf



                Next



                MsgBox (strList)



            Else



                MsgBox ("ReadDirectory() failed. LastError = " & objFTP.LastError)



            End If







            ' Download File



            Dim nRestart



            nRestart = 0







            Dim strMsg



            If objFTP.DownloadFile32("History.txt", "History.txt", nRestart) = sfFTPLib.enumError.ftpErrorSuccess Then



                strMsg = "DownloadFile() successful." & vbCrLf



                strMsg = strMsg & "LastTransferBytes = " & objFTP.LastTransferBytes32 & " B" & vbCrLf



                strMsg = strMsg & "LastTransferTime = " & objFTP.LastTransferTime & " s" & vbCrLf



                strMsg = strMsg & "LastTransferSpeed = " & objFTP.LastTransferSpeed & " B/s"



                MsgBox (strMsg)



            Else







                strMsg = "DownloadFile() failed. LastError = " & objFTP.LastError & vbCrLf



                strMsg = strMsg & "LastReplyCode = " & objFTP.LastReplyCode & vbCrLf



                strMsg = strMsg & "LastReply = " & objFTP.LastReply & vbCrLf



                MsgBox (strMsg)



            End If



        Else



            MsgBox ("ChangeDirectory() failed. LastError = " & objFTP.LastError)



        End If



        



    Else



        MsgBox ("Connect() failed. LastError = " & objFTP.LastError)



    End If



End Sub







Private Sub objFTP_OnTransferProgress32(ByVal nBytesTransferred As Long)



Label1.Caption = nBytesTransferred



End Sub

Thank you.

Problem should be fixed in latest build 1.0.1.27. Please give it a try.

-Mat

I installed the lastest 1.27 and I still have the same problem.

I'll uninstall and reboot and install again to make sure

Update...uninstalling and rebooting didn't fix the prob. I still get the same error after I compile the exe

Hello ...

Please try the new .28 build. The same approach has been used but with a different implementation.

Regards,
-Mat

Fixed thank you! I will get my boss to make the purchase.

Great DLL!!!