* Internet Auto Download Program 
Author Message
 * Internet Auto Download Program

I want to write a program that retrieves a bunch of PDF files from a web
site and put them in one of my local folders (for later viewing).  I already
know the address of the web site where I want to download from
( http://www.*-*-*.com/ ).  The filenames of the PDF files only vary by a
numeric digit.  (e.g. File1.pdf, File2.pdf).

Essentially, I want to download all the pdf files from
http://www.*-*-*.com/ , file2.pdf, etc... and put them in my
C:\pdffiles directory.

Can someone tell me how to do this?



Thu, 27 Feb 2003 17:21:56 GMT  
 * Internet Auto Download Program
Heres some code I just ripped out of some old project I had, it should
get you started, using the Inet control in VB6.

Dest$= "C:\pdffiles\"

' Get URL from list box
For Numbr = 0 To List1.ListCount - 1
Url$ = List1.List(Numbr) ' GET URL from List

' Get filename only from end of URL, save in Fn$
Fn$= StrIp(Url$) ' * USE YOUR OWN SUB ROUTINE HERE.

bFile() = Inet1.OpenURL(Url$, icByteArray) ' DOWNLOAD FILE in URL$

Do Until Inet1.StillExecuting = False ' WAIT Downloading..
 DoEvents
Loop

' SAVE DOWNLOADED FILE ..
FF = FreeFile
Open Dest$ + Fn$ For Binary Access Write As #FF
 Put #FF, , bFile()
 DoEvents
Close #FF

' get next file in list
 Erase bFile() ' CLEAR MEM
DoEvents
Next Numbr ' GET NEXT URL

Hope this helps you get started. I wrote a program that downloads
graphics files and increments the URL and saves them to my hard drive,
it comes in handy.

Ed,
http://www.edgemealsoftware.com

Quote:

>I want to write a program that retrieves a bunch of PDF files from a web
>site and put them in one of my local folders (for later viewing).  I already
>know the address of the web site where I want to download from
>(http://www.thiswebsite.com).  The filenames of the PDF files only vary by a
>numeric digit.  (e.g. File1.pdf, File2.pdf).

>Essentially, I want to download all the pdf files from
>http://www.thiswebsite.com/file1.pdf, file2.pdf, etc... and put them in my
>C:\pdffiles directory.

>Can someone tell me how to do this?



Sat, 01 Mar 2003 14:54:11 GMT  
 * Internet Auto Download Program

The first thing to do is add the "Microsoft Internet Transfer Control"
component to your project, and then place one on your form.

Then, to learn what files are available, you will have to connect
to the site, navigate to your desired directory and then issue a
DIR command.  What you get back will be a stream of data
which you will collect using the GetChunk method (See help example)

Once you have that string, you can split it up into an array, to
give you the list of files available.  Then it simply becomes
a process of looping through the array using GET to copy each
file.  Example:

cmd = "GET " & FileNames(idx) & " " & LocalDirectory & FileNames(idx)
Inet1.Execute , cmd

The cmd string, when filled out should look like this:
GET File1.pdf c:\pdffiles\file1.pdf

Note: if there are spaces in the file names, surround the file name with " (quotes)

GET File1.pdf "c:\my docs\pdf files\File1.pdf"

It will be no simple process because in just about every step
of the way you have to assume the connection may break down
and/or fail.  For example, here is a section that tries to connect
to the site, attempting 5 tries before giving up:

Note: You supply bracketed text:  <SomeText>

Public Function MakeConnection() As Boolean
Dim cnt As Long

  On Error Resume Next
  With frmMain.Inet1
    'Set Inet properties
    .URL = <ftp://YourSite.com>
    .UserName = <LogInName>
    .Password = <LogInPassword>
    'Retry connection up to 5 times if it fails
    Do
      .Execute , "CD " & <YourSiteDirectory>
       Do While .StillExecuting
          DoEvents
      Loop
      Cnt = Cnt + 1
    Loop Until Err.Number = 0 Or Cnt >= 5
  End With
  If Err.Number = 0 Then MakeConnection = True
End Function

This returns true if the connection is good, so that you
can kick off your process with something like:

If MakeConnection() Then
  If GetSiteDirectory() Then
    If GetFiles() Then
      'Success!
    Else
      'Get files failed
    End If
  Else
    'Get Directory failed
  End If
  Else
    'Make Connection failed
End If

Be prepared for several attempts at working out the bugs.
You can't control what the server is doing, you can control
what you send to the server, double check your procedures
and commands if you have problems.

HTH
LFS

Quote:

> I want to write a program that retrieves a bunch of PDF files from a web
> site and put them in one of my local folders (for later viewing).  I already
> know the address of the web site where I want to download from
> (http://www.thiswebsite.com).  The filenames of the PDF files only vary by a
> numeric digit.  (e.g. File1.pdf, File2.pdf).

> Essentially, I want to download all the pdf files from
> http://www.thiswebsite.com/file1.pdf, file2.pdf, etc... and put them in my
> C:\pdffiles directory.

> Can someone tell me how to do this?



Sat, 01 Mar 2003 19:13:40 GMT  
 * Internet Auto Download Program

Hi Jay,

an alternative to using the Ineternet transfer control is to add your own
custom user control to your app (VB6). VB6's usercontrol has an asyncread
function and a couple of events that make this stuff really easy with the
added bonus of it running asynchronously. Have a look at the AsynRead
function in the help docs, and if you need more help just post back here.


Quote:
> I want to write a program that retrieves a bunch of PDF files from a web
> site and put them in one of my local folders (for later viewing).  I
already
> know the address of the web site where I want to download from
> (http://www.thiswebsite.com).  The filenames of the PDF files only vary by
a
> numeric digit.  (e.g. File1.pdf, File2.pdf).

> Essentially, I want to download all the pdf files from
> http://www.thiswebsite.com/file1.pdf, file2.pdf, etc... and put them in my
> C:\pdffiles directory.

> Can someone tell me how to do this?



Sat, 01 Mar 2003 21:47:30 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VB Program Auto Connect To Internet?

2. Program for downloading of web pages from internet

3. Program for downloading of web pages from internet

4. Internet downloaded ActiveX program problem

5. Internet Program / download someones drive listings

6. Internet Program / download someones drive listings

7. Internet Program / download someones drive listings

8. How to multi-thread an internet download program?

9. Internet Program / download someones drive listings

10. Safe for scripting: install OCX with setup program wizard (no internet download

11. Auto Download of doc files into new doc file from a web site

12. auto download file from the web

 

 
Powered by phpBB® Forum Software