Results 1 to 13 of 13

Thread: [RESOLVED] HTTP POST a zip file

  1. #1

    Thread Starter
    Junior Member giannopo's Avatar
    Join Date
    Jan 2002
    Location
    Greece
    Posts
    27

    [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

  2. #2
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    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

  3. #3

    Thread Starter
    Junior Member giannopo's Avatar
    Join Date
    Jan 2002
    Location
    Greece
    Posts
    27

    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

  4. #4
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: HTTP POST a zip file

    do you have access to the remotee server, and can you run an ASP there?

  5. #5
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    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.

  6. #6

    Thread Starter
    Junior Member giannopo's Avatar
    Join Date
    Jan 2002
    Location
    Greece
    Posts
    27

    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

  7. #7
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: HTTP POST a zip file

    So you "can" post an ASP page up there? Does the server run ASP?

  8. #8

    Thread Starter
    Junior Member giannopo's Avatar
    Join Date
    Jan 2002
    Location
    Greece
    Posts
    27

    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

  9. #9
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    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.

  10. #10

    Thread Starter
    Junior Member giannopo's Avatar
    Join Date
    Jan 2002
    Location
    Greece
    Posts
    27

    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

  11. #11
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    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 ...

  12. #12

    Thread Starter
    Junior Member giannopo's Avatar
    Join Date
    Jan 2002
    Location
    Greece
    Posts
    27

    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

  13. #13
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    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
  •  



Click Here to Expand Forum to Full Width