Jump to content

AutoIt3 Web Server to send files


Recommended Posts

I'm working on a script to easily send files to people by sending an URL with my IP and filename, for example

I can give someone an URL like http://87.14.27.88/file1.rar

and let someone download it via http with any browser.

The download begins (I see the progress window) but it is impossible to get the file (speed 0)

If $CmdLine[0]=0 Then Exit
$file=$CmdLine[1]

TCPStartup()
$s=TCPListen(@IPAddress1, 80)

$httpAcceptSocket=-1
While 1
    If $httpAcceptSocket=-1 Then TCPCloseSocket($httpAcceptSocket)
    Sleep(100)

    $httpAcceptSocket=TCPAccept($s)
    If $httpAcceptSocket<0 Then ContinueLoop
    
    $r=TCPRecv($httpAcceptSocket, 1024)
    
    $cmd=StringLeft($r, StringInStr($r, ' ')-1)
    If $cmd<>'GET' Then ContinueLoop 
    ;$file=StringTrimLeft(StringLeft($r, StringInStr($r, 'HTTP')-2), 5)
    ;  $file is now "/file.rar"
    
    ;If Not $file Then ContinueLoop
    ;If Not FileExists($file) Or StringInStr(FileGetAttrib($file), 'D') Then ContinueLoop
    ;MsgBox(0,0,$file)
    TCPSend($httpAcceptSocket, _
'HTTP/1.1 200 OK' & @CRLF & _
'Date: Wed, 25 Apr 2007 18:14:19 GMT' & @CRLF & _
'Server: Apache' & @CRLF & _
'Last-Modified: Fri, 20 Apr 2007 10:13:09 GMT' & @CRLF & _
'ETag: "3f21b12-3b729-46289235"' & @CRLF & _
'Accept-Ranges: none' & @CRLF & _
'Content-Length: 243497' & @CRLF & _
'Connection: close' & @CRLF & _
'Content-Type: application/octet-stream' & @CRLF)
TCPSend($httpAcceptSocket, FileRead($file))
    
WEnd
TCPShutdown()

Can someone help me to find the error? (Probabily on the last TCPSend)

Thanks.

Link to comment
Share on other sites

I just want to use it to send sometimes small files to one person. Yes, the loop never ends, I forgot to add an hotkey or something like it (this is not the final version)

Should I send any special character after the HTTP header or something like that?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...