
* 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?