Sign in to follow this  
Followers 0
Marlo

Experimenting with TCP file sending.

4 posts in this topic

#1 ·  Posted (edited)

OK so for the past few days ive been working on a Remote Admin tool written entirely in AutoIt and up until now all has gone well.

So today i start work on a way for the Client to send the server a file and its ALMOST working but its throwing some strange behavior, mostly adding a few random bytes to the front and back of the file.

It sends stuff like...

NULL NULL NULL NULL 0:11

Heres the part of the code that will be recieveing the file:

Local $sReceived, $iTotalDownloaded, $iPercentage, $bDownloading = True
    Local $hFile = FileOpen($sDownloadFileName, 18) ;Creates the file that the server is about to recieve.
    ProgressOn($sTitle & " - File Transfere", "Downloading " & $sDownloadFileName, "0.0% " & $iTotalDownloaded & " of " & $iDownloadFileSize & "Bytes")
    
    While $bDownloading
        $sReceived = TCPRecv($Socket, 2000)
        If BinaryLen($sReceived) = 0 Then ContinueLoop
        $iTotalDownloaded += BinaryLen($sReceived)
        $iPercentage = Round($iTotalDownloaded / $iDownloadFileSize * 100, 1)
        FileWrite($hFile, $sReceived)
        ProgressSet($iPercentage, $iPercentage & "% " & $iTotalDownloaded & " of " & $iDownloadFileSize & "Bytes")
        If $iTotalDownloaded >= $iDownloadFileSize Then $bDownloading = False
        sleep(5)
    WEnd
    
    FileClose($hFile)
    ProgressOff()ƒoÝŠ÷ Ø   Ý…êÞ²Ø^r‡^¶­±éݲØ^~)^jëhŠ×6Local $hFile = FileOpen($sFile, 16)
Local $sBytes, $iBytesSent
Local $iTotalBytes = FileGetSize($sFile)
            
    While True
        $sBytes = FileRead($hFile, 500)
        $iBytesSent += TCPSend($hSocket, $sBytes)
        If $iBytesSent = $iTotalBytes Then ExitLoop
    WEnd

I've simplified the code a bit for posting here so i hope you can still spot if im doing anything wrong.

Thanks in advance

Regards

Edited by Marlo

Click here for the best AutoIt help possible.Currently Working on: Autoit RAT

Share this post


Link to post
Share on other sites



OK so for the past few days ive been working on a Remote Admin tool written entirely in AutoIt and up until now all has gone well.

So today i start work on a way for the Client to send the server a file and its ALMOST working but its throwing some strange behavior, mostly adding a few random bytes to the front and back of the file.

It sends stuff like...

NULL NULL NULL NULL 0:11

Heres the part of the code that will be recieveing the file:

Local $sReceived, $iTotalDownloaded, $iPercentage, $bDownloading = True
    Local $hFile = FileOpen($sDownloadFileName, 18) ;Creates the file that the server is about to recieve.
    ProgressOn($sTitle & " - File Transfere", "Downloading " & $sDownloadFileName, "0.0% " & $iTotalDownloaded & " of " & $iDownloadFileSize & "Bytes")
    
    While $bDownloading
        $sReceived = TCPRecv($Socket, 2000)
        If BinaryLen($sReceived) = 0 Then ContinueLoop
        $iTotalDownloaded += BinaryLen($sReceived)
        $iPercentage = Round($iTotalDownloaded / $iDownloadFileSize * 100, 1)
        FileWrite($hFile, $sReceived)
        ProgressSet($iPercentage, $iPercentage & "% " & $iTotalDownloaded & " of " & $iDownloadFileSize & "Bytes")
        If $iTotalDownloaded >= $iDownloadFileSize Then $bDownloading = False
        sleep(5)
    WEnd
    
    FileClose($hFile)
    ProgressOff()ƒoÝ÷ Ø  ÝêÞ²Ø^r^¶­±éݲØ^~)^jëh×6Local $hFile = FileOpen($sFile, 16)
Local $sBytes, $iBytesSent
Local $iTotalBytes = FileGetSize($sFile)
            
    While True
        $sBytes = FileRead($hFile, 500)
        $iBytesSent += TCPSend($hSocket, $sBytes)
        If $iBytesSent = $iTotalBytes Then ExitLoop
    WEnd

I've simplified the code a bit for posting here so i hope you can still spot if im doing anything wrong.

Thanks in advance

Regards

I don't know but ir might be worth using

$sReceived = TCPRecv($Socket, 2000, 1);to force binary read

Maybe make sure the data is sent as binary too.

If the number of bytes sent isn't 500 (or the same as the the number read) then you will get errors so maybe you should check for that.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

The forum search for '+tcp +file +transfer' that I'm assuming you've done...

A post that I found by looking through given search that seems to have already done what you're looking for and could serve as a guide.

Share this post


Link to post
Share on other sites

No i tried that but its still adding random bytes to the front of the file o_0

But now its getting weird as sometimes it will work perfectly and other times it will just add those random bytes. (adds about 9-11 bytes to the front of the file ONLY)

Anyone else who can shed some light on this for me?


Click here for the best AutoIt help possible.Currently Working on: Autoit RAT

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