how to copy mp3/audio file in ASP using ServerXMLHTTP

how to copy mp3/audio file in ASP using ServerXMLHTTP

am 11.01.2008 13:30:40 von 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

Re: how to copy mp3/audio file in ASP using ServerXMLHTTP

am 11.01.2008 14:33:59 von Anthony Jones

"Spydrlink" wrote in message
news:28f8520c-b530-46c3-9206-fc0ca790eb61@n20g2000hsh.google groups.com...
> 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_ 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.

--
Anthony Jones - MVP ASP/ASP.NET

Re: how to copy mp3/audio file in ASP using ServerXMLHTTP

am 11.01.2008 14:56:12 von 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.