Results 1 to 9 of 9

Thread: Download file from Internet problems [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Resolved Download file from Internet problems [RESOLVED]

    Hi all,

    I'm trying to make a program that downloads first a text file from the internet, and then some exes, and runs them (an updater program, if you like).

    I've researched on this forum a bit and downloaded a few sample programs / code snippits for this kind of thing, but I'm habing some troubles.

    Problem 1:

    A common code snippit seems to be the "Inet1.openURL" code. Here's the section in my test program:

    Code:
    Private Sub Command2_Click()
    Dim TextIn As String
    
    TextIn = Inet1.OpenURL("http://arbital24.com/Test.txt", icString)
    MsgBox TextIn
    
    End Sub
    And another, using a similar code but this time designed to actually download a file, rather than just reading the text:

    Code:
    Private Sub DownLoadFromURL(ByVal url As String, ByVal filename As String)
        '
        '   Download a file from a given URL
        '
        Dim bytes() As Byte
        Dim fnum As Integer
        Dim ftext As String
        '
        ' Download the file and load into byte array
        '
        ftext = url & filename
        bytes() = Inet1.OpenURL(ftext, icByteArray)
    
        fnum = FreeFile
        '
        '   Write the downloaded file to disk
        '
        Open "C:\" & filename For Binary Access Write As #fnum
        
        Put #fnum, , bytes()
        Close #fnum
        
    End Sub
    
    Private Sub Command3_Click()
    DownLoadFromURL "http://arbital24.com/123.exe", "123.exe"
        Unload Me
    End Sub

    With either of the code snippits, if I try and run the code and click the button, whenever it gets to the "Inet1.OpenURL" line, it comes back with an error saying "Run-time error 424 - Object required"

    Why is this? And how can I stop it? I registered the "Microsoft Internet Transfer Control 6.0" by clicking Project > Components


    Problem 2:

    I've tried this code snippit:

    Code:
    Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    Public Function DownloadFile(url As String, LocalFilename As String) As Boolean
        Dim lngRetVal As Long
        lngRetVal = URLDownloadToFile(0, url, LocalFilename, 0, 0)
        If lngRetVal = 0 Then DownloadFile = True
    End Function
    
    Private Sub Command1_Click()
    Dim TextIn As String
    Dim FF As Integer
    
    FF = FreeFile()
    
    DownloadFile "http://arbital24.com/123.exe", "c:\123.exe"
    End Sub
    But what actually downloads is a HTML file of a page. I tested this first using the "Test.txt" file, which came back with the same result. The contents of the HTML file:

    Code:
    <HTML><HEAD>
    <META NAME="description" content="">
    <META NAME="keywords" content="">
    <TITLE></TITLE>
    
    </HEAD>
    <FRAMESET ROWS="100%,*" BORDER="0" FRAMEBORDER="0">
    <FRAME SRC="http://arbital24.dyndns.org/123.exe" SCROLLING="AUTO" NAME="bannerframe" NORESIZE>
    </FRAMESET>
    <NOFRAMES>
    
    <P>
    <DIV ALIGN="CENTER"><A HREF="http://arbital24.dyndns.org/123.exe">http://arbital24.com/</A></DIV>
    </NOFRAMES>
    </HTML>
    And the same code for the Test.txt file. In both cases, opening the file in Internet explorer will download/load the .exe or .txt file

    So for this code snippit, How can I actually get it to download the contents of the file, rather than just some random HTML file?


    Thanks for any help,
    Arby


    EDIT:

    I've found that if I add to the form a blank "Inet1" object, I no longer get the "Object required" error (Problem 1). However, the file still loads (in all 3 code snippits) that blank HTML file. So, I just need to know how to make it load the actual file, and not this HTM
    Last edited by BubbleLife; Nov 24th, 2005 at 10:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width