-
Jul 25th, 2006, 03:45 PM
#1
Thread Starter
Junior Member
[RESOLVED] HTTP POST a zip file
Hi,
I have to create an ASP that send a zip file to an external server, using http post.
I know how to send an XML using http post.
what about a file (a zip in my case)??
Thanks in advance
Last edited by giannopo; Jul 26th, 2006 at 05:37 AM.
elias 
-
Jul 26th, 2006, 03:29 AM
#2
Fanatic Member
Re: HTTP POST a zip file
Elias,
As far as I know you have to use the "file" input tag -
Code:
<input type="file" name="file1" id="file1">
However there are lots of things to consider so I recommend using something like this to do the upload for you.
http://www.planetsourcecode.com/vb/s...=8525&lngWId=4
Hope this helps
Cheers Al
-
Jul 26th, 2006, 03:41 AM
#3
Thread Starter
Junior Member
Re: HTTP POST a zip file
Dear Al,
thanks for your response.
I need an automation (no form with file tag).
for example when I run an asp then the code get a zip file and post it to external server.
elias 
-
Jul 26th, 2006, 04:13 AM
#4
PowerPoster
Re: HTTP POST a zip file
do you have access to the remotee server, and can you run an ASP there?
-
Jul 26th, 2006, 04:23 AM
#5
Fanatic Member
Re: HTTP POST a zip file
I'm not sure I understand, so please forgive me if I'm wrong.
Are you trying to silently upload a file from a clients machine?
This is very much NOT allowed, which is why when using the input type "file" you cannot set the value/text. This is to stop shady types from stealing data off your computer.
-
Jul 26th, 2006, 04:25 AM
#6
Thread Starter
Junior Member
Re: HTTP POST a zip file
Nop. I dont have access.
I can hit an script file (asp, php, jsp I don't know what kind) and I need to post a zip file to these script.
something like using the file tag
<form action='www.somewhere.com/somescript' method='post'>
<input type='file' name='file1' id='file1'/>
<input type='submit'/>
</form>
but without the manual use (click browse select file then click submit)
I need to post the zip file automaticaly.
The project is to send a zip file that containts some images and a text file to a mobile provider. (is an MMS for premiere league goals)
Im not try to put a value to inout tag. I know that not allowed for input tag when the type is file.
I have already use the xmlhttp in order to post xml file. But works only for text files (txt, xml, etc) and not for binary.
Last edited by giannopo; Jul 26th, 2006 at 04:30 AM.
elias 
-
Jul 26th, 2006, 04:28 AM
#7
PowerPoster
Re: HTTP POST a zip file
So you "can" post an ASP page up there? Does the server run ASP?
-
Jul 26th, 2006, 04:33 AM
#8
Thread Starter
Junior Member
Re: HTTP POST a zip file
Nop. I don't know what kind of server is. I can't post and script code at that server.
elias 
-
Jul 26th, 2006, 05:25 AM
#9
PowerPoster
Re: HTTP POST a zip file
UPDATE OCT 26, 07 - added a new version using a VBScript Standalone .VBS File and a modified BinaryUpload.asp file. These will not work along with the older files though, also includes IP and User Agent filtering in this version. VBSASPUpload.zip
----------------------------------------------------------------
Well cant help you if you can't run a script on the remote server ... at least not unless it is ASP ..
Here is an ASP version i just threw together anyways ..
Example uses a Folder on the Remote Side called Uploads, and uses a User Folder under that called Test in this case, can be changed for various users, also can add in passwords (recommended), etc.
Write permissions are obviously required on the Remote Folders.
Upload.asp - Local Side
Code:
<%@ Language="VBScript" %>
<%
Option Explicit
Response.Buffer = True
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "cache-control","private"
Response.AddHeader "pragma", "no-cache"
Dim objStream, objHttp
Dim sUrl, sFile, sName
On Error Resume Next
sFile = "C:\Test.Zip"
sName = Right(sFile,Len(sFile)-InstrRev(sFile,"\"))
sUrl = "http://www.someaspurl.com/BinaryUpload.asp?File=" & sName & "&User=Test"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Mode = 3
objStream.Type = 1
objStream.Open
objStream.LoadFromFile(sFile)
If Err = 0 Then
Response.Write "Uploading ... please wait<br>"
Response.Flush
End If
set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
objHttp.Open "POST", sUrl, False
objHttp.SetRequestHeader "Content-Length", objStream.Size
objHttp.Send objStream.Read(objStream.Size)
If Err = 0 Then
Response.write objHttp.responseText
Else
Response.Write "Upload Error!" & vbCrLf & Err.Description
End If
objStream.Close
Set objStream = Nothing
set objHttp = Nothing
%>
BinaryUpload.asp - Remote Side
Code:
<%@ Language="VBScript" %>
<%
Option Explicit
Response.Buffer = True
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "cache-control","private"
Response.AddHeader "pragma", "no-cache"
On Error Resume Next
Dim sFile, sUser
sFile = Request("File")
sUser = Request("User")
If Len(sFile) And Len(sUser) > 0 Then
Dim objFso, objStream
Dim sUploadFolder, sUserFolder
Dim sFileName, sReturnText
On Error Goto 0
On Error Resume Next
sUploadFolder = Server.MapPath("./Uploads")
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
If objFso.FolderExists(sUploadFolder) Then
sUserFolder = sUploadFolder & "\" & sUser
If objFso.FolderExists(sUserFolder) Then
sFileName = sUserFolder & "\" & sFile
If Not objFso.FileExists(sFileName) Then
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Mode = 3
objStream.Open
objStream.Type = 1
objStream.Write Request.BinaryRead(Request.TotalBytes)
objStream.Position = 0
objStream.SaveToFile sFileName, 1
objStream.Close
Set objStream = Nothing
sReturnText = "Upload Successful"
Else
sReturnText = "File already exists"
End If
Else
sReturnText = "User does not exist"
End If
Else
sReturnText = "Upload folder does not exist"
End If
Set objFso = Nothing
Else
sReturnText = "Bad Request"
End If
If Err Then
sReturnText = "Upload Error. " & Err.Description
End If
Response.Write sReturnText
Response.End
%>
Last edited by rory; Oct 26th, 2007 at 01:14 AM.
-
Jul 26th, 2006, 05:36 AM
#10
Thread Starter
Junior Member
Re: HTTP POST a zip file
I found a VB6 code that works fine with text & binary files.
I ll try to convert it to vbscript (ASP)
Thanks again for your help.
=================
Private Sub cmdSubmit_Click()
Dim strText As String
Dim strImage As String
Dim s$
Dim strBody As String
Dim aPostData() As Byte
Dim strFileName1 As String
Dim strFileName2 As String
Dim oHttp As XMLHTTP
Dim nFile As Integer
'make use of the XMLHTTPRequest object contained in msxml.dll
Set oHttp = New XMLHTTP
'read the whole text file
strFileName1 = InputBox("Text File Name:", "Upload a file", "c:\aaa.txt")
nFile = FreeFile
Open strFileName1 For Binary As #nFile
strText = String(LOF(nFile), " ")
Get #nFile, , strText
Close #nFile
'read a GIF file
strFileName2 = InputBox("Image File Name:", "Upload a file", "c:\aaa.zip")
nFile = FreeFile
Open strFileName2 For Binary As #nFile
strImage = String(LOF(nFile), " ")
Get #nFile, , strImage
Close #nFile
'fire of an http request
'!!! adapt path in next line
oHttp.open "POST", "http://adam.codedv.com/examples/post_dump.php", False
oHttp.setRequestHeader "Content-Type", "multipart/form-data, boundary=AaB03x"
'assemble the body. send one field and two files
strBody = _
"--AaB03x" & vbCrLf & _
"Content-Disposition: form-data; name=""field1""" & vbCrLf & vbCrLf & _
"test field" & vbCrLf & _
"--AaB03x" & vbCrLf & _
"Content-Disposition: attachment; name=""FILE1""; filename=""" & strFileName1 & """" & vbCrLf & _
"Content-Type: text/plain" & vbCrLf & vbCrLf & _
strText & vbCrLf & _
"--AaB03x" & vbCrLf & _
"Content-Disposition: attachment; name=""FILE2""; filename=""" & strFileName2 & """" & vbCrLf & _
"Content-Transfer-Encoding: binary" & vbCrLf & _
"Content-Type: application/zip" & vbCrLf & vbCrLf & _
strImage & vbCrLf & _
"--AaB03x--"
'must convert to byte array because of binary zeros
aPostData = StrConv(strBody, vbFromUnicode)
'send it
oHttp.send aPostData
'check the feedback
Debug.Print oHttp.responseText
End Sub
elias 
-
Jul 26th, 2006, 05:38 AM
#11
PowerPoster
Re: [RESOLVED] HTTP POST a zip file
yeah but you asked this in the ASP section, and that code uses VB6 and requires a PHP script on the remote server ...
-
Jul 26th, 2006, 05:54 AM
#12
Thread Starter
Junior Member
Re: [RESOLVED] HTTP POST a zip file
Correct!!! I need ASP code. I will try to convert it in to ASP code (and post the ASP solution here).
About the script that the code hit (php in the sample) can be ASP, PHP, JSP.
elias 
-
Jul 26th, 2006, 08:43 AM
#13
PowerPoster
Re: [RESOLVED] HTTP POST a zip file
Hmmm .. see what i posted above?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|