K, first off most of this IS NOT my code. I modified it so that it was an auto-updater instead of just a downloader. Ive fixed numerous bugs and stuff...All you need is an inet1, listbox called lststat, label called lblstatus,command button called cmdcancel

VB Code:
  1. -------------------------------------------------
  2.  
  3. Private m_GettingFileSize     As Boolean
  4. Private m_DownloadingFile     As Boolean
  5. Private m_DownloadingFileSize As Long
  6. Private m_LocalSaveFile       As String
  7. Private m_FileSize As String
  8. Private FirstResponse As Boolean
  9. Dim ff As Integer
  10. Dim exe As String
  11. dim filesize as string
  12.  
  13. Private Sub cmdCancel_Click()
  14. 'On Error Resume Next
  15. Inet1.Cancel
  16.     Unload Me
  17. End Sub
  18.  
  19. Private Sub Form_Load()
  20. filesize = # ' Okay this is how i do it, make filesize a number, compile your program and upload it. Then see how big it is on the ftp.  Type the number in the filesize re-compile and upload. Then it will have the correct filesize.
  21. If App.PrevInstance Then
  22. End
  23. End If
  24.  
  25. Dim RemoteFileToGet As String
  26. 'Name of the updated exe
  27. RemoteFileToGet = "www.bazooka.com" 'THIS IS THE DOWNLOAD
  28.  
  29. FirstResponse = False
  30. m_FileSize = GetHTTPFileSize(RemoteFileToGet)
  31. lstStat.AddItem "Establishing file size & location..."
  32. lblStatus.Caption = "0/" & Int(m_FileSize) \ 1024 ' \/
  33. If Int(m_FileSize) \ 1024 <> filesize Then  'shows in kb instead of other stuff
  34. MsgBox Int(m_FileSize) \ 1024 & "Download size" & filesize & "Your size"
  35. m_LocalSaveFile = App.Path & "\rarfile or zip.rar"
  36. Inet1.Execute RemoteFileToGet, "GET " & Chr(34) & App.Path & "\name of .exe" & Chr(34)
  37. Else
  38. MsgBox "Your exe is updated as can be :) "
  39. lstStat.AddItem "Done."
  40. lblStatus.Caption = "0/0"
  41. End If
  42. End Sub
  43.  
  44. Private Function GetHTTPFileSize(strHTTPFile As String) As Long
  45. On Error GoTo ErrorHandler
  46.     Dim GetValue As String
  47.     Dim GetSize  As Long
  48.    
  49.     m_GettingFileSize = True
  50.    
  51.     Inet1.Execute strHTTPFile, "HEAD " & Chr(34) & strHTTPFile & Chr(34)
  52.  
  53.     Do Until Inet1.StillExecuting = False
  54.         DoEvents
  55.     Loop
  56.  
  57.     GetValue = Inet1.GetHeader("Content-length")
  58.    
  59.     Do Until Inet1.StillExecuting = False
  60.         DoEvents
  61.     Loop
  62.    
  63.     If IsNumeric(GetValue) = True Then
  64.         GetSize = CLng(GetValue)
  65.     Else
  66.         GetSize = -1
  67.     End If
  68.  
  69.     If GetSize <= 0 Then GetSize = -1
  70.  
  71.     m_GettingFileSize = False
  72.     GetHTTPFileSize = GetSize
  73. Exit Function
  74.  
  75. ErrorHandler:
  76.     m_GettingFileSize = False
  77.     GetHTTPFileSize = -1
  78.    ' MsgBox err.Number & err.Description
  79. End Function
  80.  
  81. Private Sub Inet1_StateChanged(ByVal State As Integer)
  82.  
  83. Dim vtData()  As Byte
  84. Dim FreeNr    As Integer
  85. Dim SizeDone  As Long
  86. Dim bDone     As Boolean
  87. Dim GetPerc   As Integer
  88.  
  89. Select Case State
  90.    
  91.      Case 1
  92.         lstStat.AddItem "Trying to find file..."
  93.     Case 2
  94.         lstStat.AddItem "File found"
  95.     Case 3
  96.         lstStat.AddItem "Asking for approval..."
  97.     Case 4
  98.         lstStat.AddItem "Accepted"
  99.     Case 5
  100.         lstStat.AddItem "Requesting file..."
  101.     Case 6
  102.         lstStat.AddItem "Request sent"
  103.     Case 7
  104.     If FirstResponse = False Then
  105.         lstStat.AddItem "Receiving response..."
  106.         FirstResponse = True
  107.         End If
  108.        
  109.     Case 8
  110.     If FirstResponse = False Then
  111.         lstStat.AddItem "Response received"
  112.         FirstResponse = True
  113.         End If
  114.        
  115.     Case 9
  116.         lstStat.AddItem "Disconnecting..."
  117.     Case 10
  118.         lstStat.AddItem "Disconnected"
  119.    
  120.     Case 11
  121.         lstStat.AddItem "Error downloading file"
  122.         Call cmdCancel_Click
  123.  
  124.     Case 12
  125.    
  126.     If m_GettingFileSize = True Then
  127.     Exit Sub
  128.     End If
  129.    
  130.     FreeNr = FreeFile
  131.    
  132.     Open App.Path & "\file your downloading.rar" For Binary Access Write As FreeNr
  133.                
  134.     'this shows the status in real time
  135.     'kinda fancy
  136.    
  137.                 Do While Not bDone
  138.                     vtData = Inet1.GetChunk(1024, icByteArray) ' Get next chunk.
  139.                    
  140.                     SizeDone = SizeDone + UBound(vtData)
  141.                    
  142.                     lblStatus.Caption = SizeDone \ 1024 & "kb" & "/" & m_FileSize \ 1024 & "kb" 'lets it be shown in kb instead of bytes
  143.                    
  144.                     GetPerc = (SizeDone / m_FileSize) * 100
  145.                     If GetPerc > 100 Then GetPerc = 100
  146.                     If GetPerc < 0 Then GetPerc = 0
  147.                    
  148.                     Me.Caption = "AutoUpdater - " & GetPerc & "%"
  149.                                        
  150.                     Put #FreeNr, , vtData()           'chunk wegschrijven naar bestand
  151.                     If UBound(vtData) = -1 Then
  152.                         bDone = True  'Er zijn geen chunks meer, KLAAR DUS
  153.                     Else
  154.                         DoEvents      'Yield to other processes
  155.                     End If
  156.                 Loop
  157.                
  158.                 Close FreeNr
  159.    
  160. End Select
  161. lstStat.ListIndex = lstStat.ListCount - 1
  162.  
  163. If GetPerc = 100 Then
  164. Call cmdCancel_Click
  165. End If
  166.  
  167. '    If Len(err.Description) & Len(err.Source) = 0 Then
  168.     'Print vbNullString
  169.    ' Else
  170.     ' MsgBox err.Description & " Source : " & err.Source
  171.     ' End If
  172. End Sub