how to copy mp3/audio file in ASP using ServerXMLHTTP

Discussion in 'ASP General' started by Spydrlink, Jan 11, 2008.

  1. Spydrlink

    Spydrlink Guest

    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
     
    Spydrlink, Jan 11, 2008
    #1
    1. Advertising

  2. "Spydrlink" <> wrote in message
    news:...
    > 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.

    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Jan 11, 2008
    #2
    1. Advertising

  3. Spydrlink

    Spydrlink Guest

    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.
     
    Spydrlink, Jan 11, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cgokey
    Replies:
    0
    Views:
    365
    cgokey
    Dec 30, 2005
  2. Daniel Dyer
    Replies:
    6
    Views:
    19,934
    Knute Johnson
    Jan 22, 2006
  3. Asle Frantzen

    Mp3-player - how to play an mp3?

    Asle Frantzen, Jul 8, 2003, in forum: C++
    Replies:
    5
    Views:
    672
    Kelsey Bjarnason
    Jul 22, 2003
  4. aeonsun
    Replies:
    2
    Views:
    433
    Luc The Perverse
    Mar 11, 2007
  5. HY Tech
    Replies:
    0
    Views:
    623
    HY Tech
    Sep 7, 2003
Loading...

Share This Page