#include-once
_FileReceive();Speichert die datei mit dem Original namen ab, die IP ist @IPADress1, Port ist 4324 und der Splashtext wird gezeigt
If @error Then MsgBox(48,"","Error: "&@error)
_FileReceive("EineDatei.exe","192.168.0.1",4444,0);Speichert die datei mit dem Namen "EineDatei.exe" ab, die ip ist 192.168.0.1, der Port ist 4444 und der Splashtext wird nicht angezeigt
If @error Then MsgBox(48,"","Error: "&@error)
;===============================================================================
;
; Function Name:   _FileReceive
; Description::    Receives a File from an Client (See _FileSend)
; Parameter(s):   
;$sFileName [Optional]			: The Filename to save (if default or "" then using the original File Name)
;$IP [Optional]				: The IP where the Server run, Default = @IPAdress1
;$PORT [Optional]			: The Port to use (must be the same as by _FileSend!!)
;$iSplash [Optional]			: 1(defaul) = show SplashText
; Requirement(s):  -
; Return Value(s):  On Succes Return 1
;			On faild Return -1 and @error code 1-3:
;			@error = 1: Error creating Listening socket on IP
;			@error = 2: Faild to open file
;			@error = 3: Faild to write file
; Author(s):       GtaSpider
;
;===============================================================================

Func _FileReceive($sFileName = '', $IP = @IPAddress1, $PORT = 4324,$iSplash=1)
	Local $iMainSocket, $iAccSocket = -1, $sBuff, $sRecv = "", $i = 0, $iFirstWhile = True
	TCPStartup()

	$iMainSocket = TCPListen($IP, $PORT)
	If @error Then Return SetError(1,0,-1)
	If $iSplash Then $iSplash = SplashTextOn('','Wait For Incoming...',200,20,-1,-1,1)
	While $iAccSocket = -1
		$iAccSocket = TCPAccept($iMainSocket)
		Sleep(50)
	WEnd
	$sBuff = Binary ($sBuff)
	
	If $iSplash Then ControlSetText($iSplash,'','Static1','Incoming...')
	
	While $sRecv = ""
		$sRecv = TCPRecv($iAccSocket, 2048, 1)
		$sRecv = BinaryToString ($sRecv)
	WEnd
	If $iSplash Then ControlSetText($iSplash,'','Static1','Receive File...')
	While $sRecv <> ""
		If StringInStr($sRecv, ',') And $iFirstWhile Then
			$sTmp = StringLeft($sRecv, StringInStr($sRecv, ",") - 1)
			$sRecv = StringTrimLeft($sRecv, StringLen($sTmp) + 1)
			If StringLen($sFileName) < 1 Then $sFileName = $sTmp
			$iFirstWhile = False
		EndIf
		$sBuff &= $sRecv
		$sRecv = BinaryToString (TCPRecv($iAccSocket, 2048, 1))
		If @error Then ExitLoop
	WEnd
	If $iSplash Then ControlSetText($iSplash,'','Static1','Write To File...')
	If FileExists($sFileName) Then
		$sTmp = StringSplit($sFileName, ".")
		If $sTmp[0] < 2 Then
			While 1
				$i += 1
				If Not FileExists($sFileName & "(" & $i & ")") Then
					$sFileName = $sFileName & "(" & $i & ")"
					ExitLoop
				EndIf
			WEnd
		Else
			While 1
				$i += 1
				If Not FileExists($sTmp[1] & "(" & $i & ")" & $sTmp[2]) Then
					$sFileName = $sTmp[1] & "(" & $i & ")." & $sTmp[2]
					ExitLoop
				EndIf
			WEnd
		EndIf
	EndIf
	$iFileOp = FileOpen($sFileName, 16 + 2)
	If @error Then Return SetError(2,0,-1)
	FileWrite($iFileOp, $sBuff)
	If @error Then Return SetError(3,0,-1)
	FileClose($iFileOp)
	If $iSplash Then ControlSetText($iSplash,'','Static1','Succesfull!')
	TCPCloseSocket($iAccSocket)
	TCPShutdown()
	Sleep(1000)
	Return 1
EndFunc   ;==>_FileReceive

