Results 1 to 24 of 24

Thread: Auto download?

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    48

    Question

    I have a web site that contains some pictures in JPG format.
    Is it possible to auto-download the pictures on the this web site using VB codes? Please give some tips. Thanks!

  2. #2
    Guest
    Using MSInet:

    Code:
    Dim localFile As String
    Dim RemoteFile As String
    Dim fnum As Long
    RemoteFile = "http://www.site.com/images/image.jpg"
    localFile = "c:\image.jpg"
     
        Dim b() As Byte
        Dim strURL As String
    
        ' Retrieve the file as a byte array.
        b() = Inet1.OpenURL(RemoteFile, icByteArray)
        fnum = FreeFile
        Open localFile For Binary Access _
        Write As fnum
        Put fnum, , b()
        Close fnum

  3. #3
    Lively Member quadoc's Avatar
    Join Date
    Jan 1999
    Location
    Ga, USA
    Posts
    83
    What if I don't know the file names? Is there a way to find out the file names and auto download?
    VB6(SP4), QB4.5, PDS7.0, IBM-U2

  4. #4
    Guest
    What do you mean? When it is placed on your computer, it's given the name. So you just name it to what you want.

    I don't think it's possible to start downloading files from a site unless you state what to download. Of course, you could always use MSInet for FTP and just download the whole list of files located on the site.

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    48
    Matthews,
    How do you use MSInet for FTP to down load the whole list of files? Please post some code... Thanks!

  6. #6
    Guest
    Here is an example of how to make an FTP using Inet: InetFTP

    And to download the whole list, you'll have to make your own, because that's not included. Probably something like:

    Code:
    On Error Resume Next
    For i = 0 to List1.ListCount
    Call CmdDownload_Click 'download button
    List1.ListIndex = List1.ListIndex + 1
    DoEvents
    Next i

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    48
    what if I don't have the file names? Is there a way to get all the file names of the sites and down load them? Thanks!

  8. #8
    Guest
    FTP will list all the files contained on the site. Than you save them as what they are on the list.

    I believe the link to the FTP I gave you will do that.


  9. #9
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    yuo could probably check with inet, and search the server for all .jpg extensions, then download them

  10. #10
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    If the files are on a web server and you want to get the whole list you will likely have trouble. The only time you can view the list is when you request a valid path (like http://www.microsoft.com/office/ AND the web server has no default file for the path (index or default .htm, .html, .asp or whatever) AND the web server has directory browsing turned on. then you will get a file list and you can set an array of inet controls to download them.

    Directory browsing is usually turned OFF (probably for just this reason )

    OR

    if one of the html files has the images on it (or links to it) then you can read the html page and into a list and get the images there.

    If you're using FTP the ls command will give you a list of files in that directory
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  11. #11
    Member
    Join Date
    Jul 2000
    Location
    BFE in Oregon
    Posts
    33

    Direct Quote from Books Online MSInet Control

    Applies To
    Microsoft Internet Transfer Control
    Executes a request to a remote server. You can only send requests which are valid for the particular protocol.
    Syntax
    object.Execute url, operation, data, requestHeaders

    The Execute property syntax has these parts:
    Part Description

    object An object expression that evaluates to an object in the Applies To list.

    url Optional. String that specifies the URL to which the control should connect. If no URL is specified here, the URL specified in the URL property will be used.

    operation Optional. String that specifies the type of operation to be executed. See Settings below for a list of supported operations.

    data Optional. String that specifies the data for operations (See Settings below.)
    requestHeaders Optional. String that specifies additional headers to be sent from the remote server. The format for these is:header name: header value vbCrLf

    Settings
    Note Valid settings for operation are determined by the protocol being used. The tables below are organized by protocol.

    Supported HTTP commands
    Valid settings for operation are:
    Operation Description

    GET Retrieve data from the URL specified in the URL property.

    HEAD Sends the Request headers.

    POST Posts data to the server. The data is located in the data argument. This is an alternate method to GET, for which additional instructions are specified in the data argument.

    PUT Put operation. The name of the page to be replaced is located in the data argument.

    Supported FTP commands
    Important The FTP protocol uses a single string that includes the operation name and any other parameters needed by the operation. In other words, the data and requestHeaders arguments are not used; all of the operations and their parameters are passed as a single string in the operation argument. Parameters are separated by a space. In the descriptions below, do not confuse the terms "file1" and "file2” with the data and requestHeaders arguments.
    The syntax for FTP operations is:
    operationName file1 file2.
    For example, to get a file, the following code invokes the Execute method, which includes the operation name ("GET"), and the two file names required by the operation:

    Inet1.Execute "FTP://ftp.microsoft.com", _
    "GET Disclaimer.txt C:\Temp\Disclaimer.txt"

    Note File names that include embedded spaces are not supported.
    ..
    Valid FTP settings for operation are:
    Operation Description

    CD file1 Change Directory. Changes to the directory specified in file1.

    CDUP Change to parent directory. Equivalent to "CD.."

    CLOSE Closes the current FTP connection.

    DELETE file1 Deletes the file specified in file1.

    DIR file1 Directory. Searches the directory specified in file1. (Wildcards are permitted but the remote host dictates the syntax.) If no file1 is specified, a full directory of the current working directory is returned.Use the GetChunk method to return the directory data.

    GET file1 file2 Retrieves the remote file specified in file1, and creates a new local file specified in file2.

    LS file1 List. Searches the directory specified in file1. (Wildcards are permitted but the remote host dictates the syntax.) Use the GetChunk method to return the file directory data.

    MKDIR file1 Make Directory. Creates a directory as specified in file1. Success is dependent on user privileges on the remote host.

    PUT file1 file2 Copies a local file specified in file1 to the remote host specified in file2.

    PWD Print Working Directory. Returns the current directory name. Use the GetChunk method to return the data.

    QUIT Terminates the current user.

    RECV file1 file2 Retrieves the remote file specified in file1, and creates a new local file specified in file2. Equivalent to GET.

    RENAME file1 file2 Renames the remote file named in file1 to the new name specified in file2. Success is dependent on user privileges on the remote host.

    RMDIR file1 Remove Directory. Removes the remote directory specified in file1. Success is dependent on user privileges on the remote host.

    SEND file1 file2 Copies a local file, specified in file1, to the remote host, specified in file2. Equivalent to PUT.

    SIZE file1 Returns the size of the directory specified in file1.

    Return Type
    None

    Remarks
    Many commands listed above can be carried out only if the user has privileges on the host server. For example, anonymous FTP sites will not allow anyone to delete files or directories.

    You want to use the LS operation with *.jpg or whatever image type you want. And using the GetChunk operation will feed you all the files that are jpg's then you can Get them however you want.
    Glacius Cool
    Concept Designer
    VB5sp4,VC++6sp3

  12. #12
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    yeah I mentioned the LS command... but you can't ftp to a web server!
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  13. #13

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    48
    paul282, How do you read the HTML page with VB? Thanks!

  14. #14
    Guest
    laura, using MSInet control:

    Code:
    Text1.text = Inet1.OpenURL("http://www.site.com")
    But that will not always work. It's better to use Webbrowser to get the source. Sometimes MSInet will timeout or not get the whole page, while the Webbrowser Control will always get all of it.

    Code:
    Text1.Text = Webbrowser1.Document.documentElement.innerHTML

  15. #15

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    48
    Matthew, I'm new to the webbrowser control. How do you use the webbrowser? Please post some code. Thanks!

  16. #16
    Guest
    Here are the basics:

    Code:
    'Go to the previous webpage
    WebBrowser1.GoBack
    'Go to the forward webpage
    WebBrowser1.GoForward
    'Go to the default IE home
    WebBrowser1.GoHome
    'Go to the default search page
    WebBrowser1.GoSearch
    'Refresh the current webpage
    WebBrowser1.Refresh
    'Navigate to a webpage
    WebBrowser1.Navigate "www.YourSite.com"
    That's basically all you need to make a Webbrowser.

  17. #17

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    48
    Matthew, I tried the code:
    Text1.Text = Webbrowser1.Document.documentElement.innerHTML
    but I get an error '91'-object variable or with block variable not set. I do have a control on the form and a text box. Any ideas? Thanks!

  18. #18
    Guest
    You say you put the Webbrowser Control on the form. I am not sure then. But I sent you an example of how to do it.

    Hope that helps.

  19. #19

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    48
    Why do I get an error when I try this?
    Text1.text = Webbrowser1.Document.documentElement.innerHTML

    I do have Webbrowser1 on the form and a text box. Does anyone familiar with this?

  20. #20
    Guest
    Did you navigate to a site before getting the source?

  21. #21
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Thumbs up Laura, try this ...

    Put a textbox, webbrowser control and a command button in your program and then use this code:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        WebBrowser1.Navigate2 "www.yahoo.com"
    End Sub
    
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        If pDisp Is WebBrowser1.Object Then
            Text1.Text = WebBrowser1.Document.documentElement.innerHTML
        End If
    End Sub
    That should do the trick.

    All the best.

  22. #22

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    48
    Dear all,

    I tried the suggestion from OneSource and it works. I think the problem was I try to get the source page before it finish loading it or something like that. Thanks everyone for helping me out...

  23. #23
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    i think the inet way is the easiest, but, the choice is yours.

  24. #24
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Originally posted by Matthew Gates
    Originally posted by da_silvy
    i think the inet way is the easiest, but, the choice is yours.
    Yeah, but MSInet will timeout sometimes and not get the whole page. So you will be left with half of the html source, while if you were to use the Webbrowser control, you could get all of the source always. Of course, you'd always have to navigate to the site too, but if you want the whole source, than it's worth it.
    really, i was unaware of that

    oh well,
    you learn something new every day!

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