ASP to download from one website to another

B

Brent Billups

I am trying to download files from one website to another for purposes
of caching. In trying to do this, I created a VB dll component (using
VB6), that used URLDownloadToFile, to allow me to download the file
onto the receiving site. The sending site supports an ASP page that
allows the file to be downloaded.

The component works fine when run in debugging mode, placing the file
as expected. But when not debugging (but registered), it reports that
the file has been downloaded, but the file is not there.

I would be happy with a fix or a better solution.
 
R

Ray at

Hi Brent,

I'm not trying to turn you away from this group or anything, but I think
that you'll have much better luck getting help with this if you take it to a
VB group. If a component doesn't perform the task it's suppose to perform,
ASP code will likely not help you. Unless, of course, if you have On Error
Resume Next in there or it's an IIS permissions issue.

Ray at home
 
S

Steven Burn

Can you post the code your using to download and save the file? (will make
it much easier to diagnose for you)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
 
B

Brent Billups

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top