Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Transfer file to external server


Message #1 by "Rasmus Pedersen" <rp@m...> on Wed, 2 Oct 2002 15:59:11 +0200
Hi all

I am working on a project were i need to send an XML document to a external webserver, using the HTTP protocol. The interface has to
be a HTTP POST FORM.
I have made a script which creates and saves and XML file to the server (our server). This document i would like send to an external
HTTP adress. When i build up a html page containing a form with  ContentType = "multipart/form-data", it work just fine. But since
all the files is stored server side, the user can not browse for these files. So i would like to send the XML file directly as a
POST using the HTTP.  But this is not possible since you not can use the VALUE parameter of and inputtype FILE. 

I have tried using the AspHTTP 3.X server component from ServerObjects inc., which can POST files to and external HTTP URL - but i
can't figure out how to send the file. 

Can anyone help or has any ideas??

Regards

Rasmus Lund Pedersen
Senior Programmer
M&P Internetbureau
email: rp@m...
tlf: + 45 33 13 10 40
fax: + 45 33 11 03 07

Message #2 by "Ben Herron" <Ben.Herron@c...> on Thu, 3 Oct 2002 01:02:26
This VB function transfers a file to a Web Server using HTTP protocol. It 
would not take much to convert it to ASP.

Public Function CopyFileToWeb(sLocalFile As String, sFileURL As String, 
sDomain As String, sUser As String, sPassword As String) As Boolean

Dim xmlhttp As MSXML2.XMLHTTP40
Dim FSO As Scripting.FileSystemObject
Dim TextFile As Scripting.TextStream
Dim sContents As String

On Error GoTo ErrorHandler

CopyFileToWeb = False ' Default to failure.

' Read the local file into a string.
Set FSO = New Scripting.FileSystemObject
Set TextFile = FSO.OpenTextFile(sLocalFile, ForReading, False)
sContents = TextFile.ReadAll()
TextFile.Close
Set TextFile = Nothing
Set FSO = Nothing

Set xmlhttp = New MSXML2.XMLHTTP40

xmlhttp.Open "PUT", sFileURL, False, sDomain & "\" & sUser, sPassword
xmlhttp.Send sContents

Debug.Print "Status: " & xmlhttp.Status & " StatusText: " & 
xmlhttp.statusText

Select Case xmlhttp.Status
Case 200, 201
Case Else
    LogError "Failed to CopyFileToWeb URL: " & sFileURL
    GoTo ExitHandler
End Select

CopyFileToWeb = True ' Successful

ExitHandler:
'-----------
Set xmlhttp = Nothing
Exit Function

ErrorHandler:
'------------
LogError
GoTo ExitHandler

End Function


> Hi all

I am working on a project were i need to send an XML document to a 
external webserver, using the HTTP protocol. The interface has to be a 
HTTP POST FORM.
I have made a script which creates and saves and XML file to the server 
(our server). This document i would like send to an external HTTP adress. 
When i build up a html page containing a form with  ContentType 
= "multipart/form-data", it work just fine. But since all the files is 
stored server side, the user can not browse for these files. So i would 
like to send the XML file directly as a POST using the HTTP.  But this is 
not possible since you not can use the VALUE parameter of and inputtype 
FILE. 

I have tried using the AspHTTP 3.X server component from ServerObjects 
inc., which can POST files to and external HTTP URL - but i can't figure 
out how to send the file. 

Can anyone help or has any ideas??

Regards

Rasmus Lund Pedersen
Senior Programmer
M&P Internetbureau
email: rp@m...
tlf: + 45 33 13 10 40
fax: + 45 33 11 03 07


  Return to Index