Jump to content
Sign in to follow this  

Sending files over LAN using TCP

Recommended Posts

Hi all,

I'm currently working on a server-client script for sending files over the network(LAN) and after that, I can remotly run them or whatever.

Now I got this all working, but now during testing, I start to see that sometimes the program 'loses' some bytes on bigger files (10MB+).

My guess is that this is possible because of other traffic on the network?

If I'm wrong, can anyone provide me with an explanation for this?

If I'm right, can anyone push me in the direction of how to avoid these losses?

If more info, codes, explenation is needed, please ask :)

Thank you,


Share this post

Link to post
Share on other sites

When you say "loses some bytes on bigger files" is any information being lost, or is file size changing with no lost functionality? I ask because I have seen this when changing between windows versions (win7 moving files to server 2003) the files will get smaller when sent to the older OS because there are less available file attributes. If this is the case you may want to look into calling the "Robocopy" command in your script rather than using FileCopy() as its very good at pulling all attributes associated with a file (even between OS versions)

Share this post

Link to post
Share on other sites

Hi, thanks for the answer.

-It also loses it's functionality.

I got PDF's that I can't open anymore, another PDF where the front page is empty, a ZIP file that says: Error:

unable to process the headers in the archive.

-It's not like it loses 1 byte / MB or so. It's random. Check the screenshots for more info.

1st picture: 1st try

2nd picture: 2nd try

3rd picture: original size of files

Edited by THAErAsEr

Share this post

Link to post
Share on other sites

I cant help ya then. im still kinda nooby myself and dont understand the inner workings of autoIT file limits and the like. may be something with max file size of a file?

Share this post

Link to post
Share on other sites

If more info, codes, explenation is needed, please ask :)

Thank you,


Hi, THAErAsEr, welcome to the forum. I will offer that it is always a good idea to provide code when requesting assistance, either your complete code or a short reproducer. You will always receive more help if forum members have code to go through.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post

Link to post
Share on other sites

I'm sure I have seen a post around the forum before about this topic. Search _SendFile or something similar.

UDF List:

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post

Link to post
Share on other sites

It does not accept my screenshot :/

@guinness, do they mention this problem too? Because I allready looked trough some of the _SendFile and TCP scripts allready.

It does not look like a coding problem, because sending the same file over and over again, keeps getting me different file sizes. But that's just my idea offcourse :)


Client code for sending messages and files:

Func SendMessage($sendType, $sendMessage)
   ;Type selection
   Case $sendType="#MSG#"
   $sendTypeLabel="MSG > "
   Case $sendType="#CMD#"
   $sendTypeLabel="CMD > "
   Case $sendType="#SAF#"
   $sendTypeLabel="File Transfer : "
   $sendFileHandler=FileOpen($sendFile, 16)
   EditControl($sendTypeLabel, $sendMessage)
   $sendFileBinary=Binary("#SAF#" & StringTrimLeft($sendFile, StringInStr($sendFile, "\", 2, -1))&"," & FileRead($sendFile) & "#/SAF#")
   ;EditControl("TEST > ", $sendFileBinary)                        ;TESTING
   ;EditControl("TEST > ", "#SAF#" & StringTrimLeft($sendFile, StringInStr($sendFile, "\", 2, -1))&"," & FileRead($sendFile) & "#/SAF#")   ;TESTING
   While BinaryLen($sendFileBinary)
   $sendBytes = TCPSend($startConnect, $sendFileBinary)
   If @error Then MsgBox(16, "Error", "Failed to send file.")
   GUICtrlSetData($GUIControlIDProgress, $temptest) ; BinaryLen($sendFileBinary) / $sendFileBinaryStart
   $sendFileBinary = BinaryMid ($sendFileBinary, $sendBytes + 1, BinaryLen ($sendFileBinary) - $sendBytes)
   GUICtrlSetData($GUIControlIDProgress, 0)
   If $sendType<>"#SAF#" then
   ;Input control
   TCPSend($startConnect, StringToBinary($sendType & $sendMessage, 4))
   ;GUI handling
   If $sendMessage<>"" And $sendType <> "#SAF#" Then
   EditControl($sendTypeLabel, $sendMessage)
   ElseIf $sendType = "#SAF#" Then
   EditControl($sendTypeLabel, "Completed.")
   ControlFocus("My Cliënt", "", 4)

Server code for receiving the message/file:

Func receiveData($repeat = False)
   If $recBinary <> "" Then
   ;rtf(BinaryToString($recBinary) & " = " & StringToBinary($recBinary))
   If $repeat = False Then
Func GUILoop()
   While 1
Func readMessage($recBinary2)
   $recString=BinaryToString($recBinary2, 4)
   $recMessage=StringMid($recString, 6)
   Case $recType="#MSG#"
   $recTypeLabel="MSG > "
   Case $recType="#CMD#"
   $recTypeLabel="CMD > "
   If ProcessExists("cmd.exe") = 0 Then
   WinActivate("Remote CMD")
   Case $recType="#SAF#"
   $recTypeLabel="File Transfer : "
   $fileArray = StringSplit($recMessage, ",")
   $recMessage = $fileArray[2]
   While 1
   $endPosition=StringInStr($recMessage, "#/SAF#", 0, -1)
   if $endPosition > 0 Then
      $recMessage=StringTrimRight($recMessage, 6)
   If $endFound Then ExitLoop
   writeFile($fileLocation, $fileTitle, $recBuffer)
   If $recMessage <> "" And $recType <> "#SAF#" Then
   EditControl($recTypeLabel, $recMessage)
   ElseIf $recType = "#SAF#" Then
   EditControl($recTypeLabel, $fileTitle & " saved at " & $fileLocation & ".")
   ;Clear vars
   $recBuffer = ""
   $recMessage = ""
   $recString = ""
   $recTypeLabel = ""
   $recType = ""
   $fileTitle = ""
   ;$fileLocation = "" ;constante
   $fileArray = ""
   $endFound = False
   $endPosition = ""
Func writeFile($fileLocation, $fileTitle, $fileData, $writeMode=$writeModeErase)
   $fileHandle=FileOpen($fileLocation & $fileTitle, $writeMode)
   FileWrite($fileHandle, $fileData)

Thank you all allready!

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...