how to copy mp3/audio file in ASP using ServerXMLHTTP

S

Spydrlink

I've been looking everywhere and can't seem to find a straight answer
so I'm hoping someone here can give me some specific code with a
straight answer.

Here's what I need to do...don't have any flexibility in this either
so I have to make this work:

1) I'm trying to use ServerXMLHTTP to check for the existence of
an .mp3 file from a remote server
2) If it exists then grab the file.
3) Copy that .mp3 file to another remote server (If ServerXMLHTTP can
do that, great, if not, I'm cool with FSO).

Now, I don't have the read part yet, but I'm still having problems
with the other parts. Here's what I have so far that is not working:

dim strMP3File, objXMLHTTP
Set objXMLHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXMLHTTP.Open "GET", "http://somepath.com/somefile.mp3", False '
objXMLHTTP.Send
strMP3File = objXMLHTTP.responseBody

Dim objFSO, objFile
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile strMP3File, "\\somepath\somefolder\"
Set objFSO = Nothing

objXMLHTTP.Close
Set objXMLHTTP = Nothing
 
A

Anthony Jones

Spydrlink said:
I've been looking everywhere and can't seem to find a straight answer
so I'm hoping someone here can give me some specific code with a
straight answer.

Here's what I need to do...don't have any flexibility in this either
so I have to make this work:

1) I'm trying to use ServerXMLHTTP to check for the existence of
an .mp3 file from a remote server
2) If it exists then grab the file.
3) Copy that .mp3 file to another remote server (If ServerXMLHTTP can
do that, great, if not, I'm cool with FSO).

Now, I don't have the read part yet, but I'm still having problems
with the other parts. Here's what I have so far that is not working:

dim strMP3File, objXMLHTTP
Set objXMLHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXMLHTTP.Open "GET", "http://somepath.com/somefile.mp3", False '
objXMLHTTP.Send
strMP3File = objXMLHTTP.responseBody

Dim objFSO, objFile
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile strMP3File, "\\somepath\somefolder\"
Set objFSO = Nothing

objXMLHTTP.Close
Set objXMLHTTP = Nothing

The responseBody of the request will be a byte array holding the contents of
the mp3 file itself not merely some file name that you can somehow copy
from. Try this:-

Dim oXMLHTTP
Dim oStream

Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")

oXMLHTTP.Open "GET", "http://somepath.com/somefile.mp3", False
oXMLHTTP.Send

If oXMLHTTP.Status = 200 Then
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write oXMLHTTP.responseBody
oStream.SaveToFile "\\somepath\somefolder\somefile.mp3"
oStream.Close
End If

Note that in order for this code to work the security token under which this
code runs must have access to the network and approriate rights on the
somefolder share and physical folder that it exposes.

Typically with anonymous access to an ASP page the IUSR_<machinename> user
account used doesn't have this level of access. Therefore you will need to
do one of these two things:-

1) Turn on windows intergrated access for the page and turn off anonymous
access. This then requries the user making the request to the page to have
the approriate rights on the network share.

2) Configure the anonymous access of the page to use a user account that has
the required access rights.
 
S

Spydrlink

That seems to work! Excellent. Well, I know it works, b/c I've tested
it on a local dev server, but now I just need to get my permissions
set right on the remote server and all will be well.

Thanks again.
 

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
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top