I think this is an ASP or IIS related problem, because it the VB code
works fine when the component is run stand-alone or in debug mode for
the ASP; it only fails when used in an ASP page.
Here is the code to see if that helps. There have been minor name
changes from the original, (to protect the guilty ;->) The sample ASP
page just attempts to download the google logo to the temp directory
on the C: drive.
I added logging to the VB code to try to diagnose the problem. The
logging works fine, notes no error from the download, but the file
isn't present.
VB Code (from the file GetFile.cls):
'Declare from the API
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 GetFile(getURL As String, destPath As String) As
Boolean
Dim myFSO As scripting.FileSystemObject
Dim downloadResult as Long
Dim textFile As scripting.TextStream
On Error GoTo GetFile_ERROR
'Get FSO for tests
Set myFSO = New scripting.FileSystemObject
'Create log file
Set textFile = myFSO.CreateTextFile("C:\temp\gdsgetfile.log")
textFile.WriteLine "Starting log " & CStr(Now)
'Check if it is already there, then don't need it
If myFSO.FileExists(destPath) Then
textFile.WriteLine "Found the file at the beginning"
GetFile = True
Else
'File doesn't currently exist
textFile.WriteLine "Trying to download the file"
downloadResult = URLDownloadToFile(0, getURL, destPath, 0,
0)
If downloadResult = 0 Then
textFile.WriteLine "Download noted successful to " &
Chr(34) & myResult & Chr(34) & ", checking for the file"
GetFile = myFSO.FileExists(destPath)
If GetFile Then
textFile.WriteLine "Found the file"
Else
textFile.WriteLine "File not found where expected"
End If
Else
textFile.WriteLine "Failed to download the file"
GetFile = False
End If
End If
textFile.Close
Set textFile = Nothing
Exit Function
GetFile_ERROR:
On Error Resume Next
If Not textFile is Nothing Then
textFile.WriteLine "Encountered error #" & CStr(Err.Number)
& " - " & Err.Description & " @ " & Err.Source
End If
Err.Clear
GetFile = False
End Function
ASP Code (from file GetFile.asp):
<%@ Language = "VBScript" %>
<% Response.Buffer = True %>
<html>
<%
Dim ws
Dim gotFile
Set ws = Server.CreateObject("MyGetFile.GetFile")
gotFile = ws.GetFile("
http://www.google.com/images/logo.gif",
"C:\Temp\google-logo.gif")
If gotFile Then
Response.Write "Got File."
Else
Response.Write "Failed to get file."
End If
Set ws = Nothing
%>
</HTML>