Sign in to follow this  
Followers 0
kj2

Http upload help

1 post in this topic

#1 ·  Posted (edited)

Hello, i'm trying make a http upload for a sendspace dropbox.

My code is this:

#include <HTTP.au3>
#include <INet.au3>
$Dropbox = "ifb3np"
$source = _INetGetSource("http://www.sendspace.com/dropbox/"&$Dropbox)
$suc = StringSplit($source, '"')
For $l = 1 To $suc[0]
    If StringInStr($suc[$l], "dropboxupload?") Then
    $sUrl=StringSplit($suc[$l], '/')
    $host=$sUrl[3]
    $vars=$sUrl[4]
    EndIf
Next
;$host = "fsxxx.sendspace.com"
$port = "80"
$page = "/"
;$vars = "dropboxupload?SPEED_LIMIT=0&amp;MAX_FILE_SIZE=2096103424&amp;UPLOAD_IDENTIFIER=xxxxxxxxxxxxxxxxxx&amp;DESTINATION_DIR=x"

$url = $page&$vars
$socket = _HTTPConnect($host, $port)
$get = _HTTPPost_File($host,$url,$socket,"C:\path\file.zip", "userfile",$Dropbox)
$recv = _HTTPRead($socket,1)
MsgBox(0, "Info", "Data received:" & @CRLF & $recv[4] & @CRLF)


Func _HTTPPost_File($host, $page, $socket = -1, $file = "", $fieldname = "",$DBid = "")
    Dim $command
    
    If $socket == -1 Then
        If $_HTTPLastSocket == -1 Then
            SetError(1)
            Return
        EndIf
        $socket = $_HTTPLastSocket
    EndIf
    
    $contenttype = _HTTPPost_contenttype($file)
    
; Maybe this can be done easier/better?
    $boundary = "------"&Chr(Random(Asc("A"), Asc("Z"), 3))&Chr(Random(Asc("a"), Asc("z"), 3))&Chr(Random(Asc("A"), Asc("Z"), 3))&Chr(Random(Asc("a"), Asc("z"), 3))&Random(1, 9, 1)&Random(1, 9, 1)&Random(1, 9, 1)
    
    $fileopen = FileOpen($file, 0); Open in read only mode
    $fileread = FileRead($fileopen)
    FileClose($fileopen)
        
    $extra_commands = "--"&$boundary&@CRLF
    $extra_commands &= "-----------------------------"&$boundary &@CRLF
    $extra_commands &= 'Content-Disposition: form-data; name="hosteddropbox"'&@CRLF
    $extra_commands &= @CRLF
    $extra_commands &= $DBid
    $extra_commands &= "-----------------------------"&$boundary &@CRLF
    $extra_commands &= 'Content-Disposition: form-data; name="js_enabled"'&@CRLF
    $extra_commands &= @CRLF
    $extra_commands &= 1
    $extra_commands &= "-----------------------------"&$boundary &@CRLF
    $extra_commands &= "Content-Disposition: form-data; name="""&$fieldname&"""; filename=""" & $file & """" &@CRLF
    $extra_commands &= "Content-Type: "&$contenttype&@CRLF&@CRLF
    $extra_commands &= $fileread&@CRLF
    $extra_commands &= "--"&$boundary&"--"
    
    Dim $datasize = StringLen($extra_commands)
    
    $command = "POST "&$page&" HTTP/1.1"&@CRLF
    $command &= "Host: " &$host&@CRLF
    $command &= "User-Agent: "&$_HTTPUserAgent&@CRLF
    $command &= "Connection: close"&@CRLF
    $command &= "Content-Type: multipart/form-data; boundary="&$boundary&@CRLF
    $command &= "Content-Length: "&$datasize&@CRLF&@CRLF
    $command &= $extra_commands
    
;debug info
    If FileExists("output.txt") Then FileDelete("output.txt")
    $file = FileOpen("output.txt", 1)
    FileWrite($file, $command)
    FileClose($file)
;end debug info
    
    Dim $bytessent = TCPSend($socket, $command)
    
    If $bytessent == 0 Then
        SetExtended(@error)
        SetError(2)
        return 0
    EndIf
    
    SetError(0)
    Return $bytessent
EndFunc

Func _HTTPPost_contenttype($file = "")
    $fileextension = StringRight($file,4)
; I blieve these are the only 2 types that matter when uploading
    Switch $fileextension
        Case ".txt"
            $contenttype = "text/plain"
        Case Else
            $contenttype = "application/octet-stream"
        EndSwitch
    Return $contenttype
EndFunc

The upload folder is this:

http://www.sendspace.com/folder/nfoo8j

My problem is that when i execute the code, the uploads haven't success .

may any body helpme with it?

thanks

kj

HTTP.au3

Edited by kj2

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0