SOLVED - VB6 OnTransferProgress

This forum is not monitored by the SmartFTP staff. If you have a license please contact technical support by email.
Gambit
Posts: 12
Joined: Tue Apr 19, 2005 9:54 pm

SOLVED - VB6 OnTransferProgress

Post by Gambit » Tue Apr 19, 2005 9:59 pm

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!

Gambit
Posts: 12
Joined: Tue Apr 19, 2005 9:54 pm

Re: SOLVED - VB6 OnTransferProgress

Post by Gambit » Thu May 05, 2005 10:38 pm

I've tryied this but I get nothing.

Code: Select all

Private Function objFTP_OnTransferProgress32(nBytesTransferred As Byte)



    Label1.Caption = nBytesTransferred



End Function

Am I way off here?

Gambit
Posts: 12
Joined: Tue Apr 19, 2005 9:54 pm

Re: SOLVED - VB6 OnTransferProgress

Post by Gambit » Fri May 06, 2005 5:46 pm

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:

Code: Select all

Dim WithEvents objFTP As FTPConnection

then on form load:

Code: Select all




Set objFTP = New FTPConnection




You will now have all the functions for objFTP

Code: Select all

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

mb
Posts: 12026
Joined: Thu Oct 11, 2001 1:24 pm
Display name: Mat (SmartFTP)
Contact:

Re: SOLVED - VB6 OnTransferProgress

Post by mb » Sat May 07, 2005 1:20 am

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

Gambit
Posts: 12
Joined: Tue Apr 19, 2005 9:54 pm

Re: SOLVED - VB6 OnTransferProgress

Post by Gambit » Thu May 26, 2005 4:22 pm

HELP NEW PROBLEM!!!!

If I do this route:

Put this in the declarations:

Code: Select all

Dim WithEvents objFTP As FTPConnection

then on form load:

Code: Select all




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

Code: Select all

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!

mb
Posts: 12026
Joined: Thu Oct 11, 2001 1:24 pm
Display name: Mat (SmartFTP)
Contact:

Re: SOLVED - VB6 OnTransferProgress

Post by mb » Thu May 26, 2005 5:13 pm

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

Gambit
Posts: 12
Joined: Tue Apr 19, 2005 9:54 pm

Re: SOLVED - VB6 OnTransferProgress

Post by Gambit » Thu May 26, 2005 6:33 pm

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

Code: Select all

'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

mb
Posts: 12026
Joined: Thu Oct 11, 2001 1:24 pm
Display name: Mat (SmartFTP)
Contact:

Re: SOLVED - VB6 OnTransferProgress

Post by mb » Thu May 26, 2005 6:39 pm

Thank you.

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

-Mat

Gambit
Posts: 12
Joined: Tue Apr 19, 2005 9:54 pm

Re: SOLVED - VB6 OnTransferProgress

Post by Gambit » Thu May 26, 2005 7:20 pm

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

mb
Posts: 12026
Joined: Thu Oct 11, 2001 1:24 pm
Display name: Mat (SmartFTP)
Contact:

Re: SOLVED - VB6 OnTransferProgress

Post by mb » Fri May 27, 2005 6:27 am

Hello ...

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

Regards,
-Mat

Post Reply