#Region ;==> Includes
#include <Array.au3>
#include <Debug.au3>
#include <FontConstants.au3>
#include <FTPEx.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <ProgressConstants.au3>
#include <StringConstants.au3>
#include <WinAPI.au3>
#include <WinAPIMisc.au3>
#include <WindowsConstants.au3>
;#include <_DownloadWithProgress.au3>
#EndRegion ;==> Includes

#Region ;==> Global
Global $g_hMyGUI, $g_idProgressBarCtrl, $g_LaProz, $g_idBtn_Cancel

Global $g_hFTPOpen = -1, $g_hFTPConnect = -1, $g_hWININET = DllOpen("wininet.dll"), $g_pCallback = -1

Global Const $g_iINTERNET_OPTION_CONNECT_TIMEOUT = 2
Global Const $g_iINTERNET_OPTION_RECEIVE_TIMEOUT = 6
Global Const $g_ERROR_INTERNET_NAME_NOT_RESOLVED = 12007 ; The server name could not be resolved.

Global	$g_iValue_CONNECT_TIMEOUT = 0xFFFFFFFF	; timer = OFF
; Sets or retrieves an unsigned long integer value that contains the time-out value, in milliseconds, to use for Internet
; connection requests. Setting this option to infinite (0xFFFFFFFF) will disable this timer. If a connection request takes longer
; than this time-out value, the request is canceled. When attempting to connect to multiple IP addresses for a single host (a
; multihome host), the timeout limit is cumulative for all of the IP addresses. This option can be used on any HINTERNET handle,
; including a NULL handle. It is used by InternetQueryOption and InternetSetOption.

Global	$g_iValue_RECEIVE_TIMEOUT = 0xFFFFFFFF	; timer = OFF
; Sets or retrieves an unsigned long integer value that contains the time-out value, in milliseconds, to receive a response to a
; request. If the response takes longer than this time-out value, the request is canceled. This option can be used on any
; HINTERNET handle, including a NULL handle. It is used by InternetQueryOption and InternetSetOption.


; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
; Hier die Einstellungen für deinen FTP-Server eintragen...
; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Global	$g_sServer = 'ftp.mozilla.org', _
		$g_iFTP_PORT = 21, _
		$g_sUsername = '', _
		$g_sPass = ''

Global	$g_iAttempts = 5	; Anzahl der Verbindungsversuche
Global	$g_iDelay = 3		; Pause in Sekunden zwischen den Verbindungsversuchen

Global	$g_aFTP_ListEx[0][2], $g_sCurrentDir = "", $g_sRemoteCurrentPath = ""
Global	$g_RemoteFileFullPath = "/pub/firefox/releases/39.0/win32/de/Firefox Setup 39.0.exe"
Global	$g_sLocalPathName = @ScriptDir
Global	$g_sLocalFileName = "Firefox_Setup_39.0.exe"
; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

#EndRegion ;==> Global

_main()

Func _main()
	_DebugSetup('MyFTP Control', True)
	__ModifyDebugWin()

	_Open_FTP_Session()					; Wenn Fehler, dann Exit(1)
	_SetInternetOptions()				; Wenn Fehler, dann Exit(2)
	_Check_InternetOptions()			; Testen, ob die Einstellungen gesetzt wurden; nicht wirklich nötig, da _SetInternetOptions() ohne Fehler ausgeführt wurde.
	_Setup_FTPStatusCallbackHandler()	; Wenn Fehler, dann Exit(3)
	_Connect_FTP_Server()				; Wenn Fehler, dann Exit(4)
	_Get_FTP_CurrentDir()				; Wenn Fehler, dann Exit(5)

	Local $aSplitRemoteFileFullPath = StringSplit($g_RemoteFileFullPath, "/", $STR_NOCOUNT)
	$aSplitRemoteFileFullPath[0] = "/"
	If $g_sCurrentDir <> "/" Then _Set_FTP_CurrentDir($aSplitRemoteFileFullPath[0])							; Wenn Fehler, dann Exit(7)
	$g_sRemoteCurrentPath = "/"
	For $i = 1 To UBound($aSplitRemoteFileFullPath) -2
		_Get_FTP_DirListEx()																				; Wenn Fehler, dann Exit(6)
		Local $iIndex = _ArraySearch($g_aFTP_ListEx, $aSplitRemoteFileFullPath[$i], 1, 0, 0)
		ConsoleWrite(StringFormat("%26s %20s %5d %1s %1d %6s %26s", _
		$aSplitRemoteFileFullPath[$i], " --> $g_aFTP_ListEx[", $iIndex, "][", 0, "] --> ", $g_aFTP_ListEx[$iIndex][0] & @LF))

		If $iIndex > -1 Or $g_aFTP_ListEx[2] = 16 Then	; ist ein Directory
			_Set_FTP_CurrentDir($aSplitRemoteFileFullPath[$i])												; Wenn Fehler, dann Exit(7)
			$g_sRemoteCurrentPath &= $g_sCurrentDir & "/"
			_DebugOut("OK - RemoteCurrentPath  = '" & $g_sRemoteCurrentPath & "'")
		EndIf
	Next
	If FileExists($g_sLocalPathName) Then
		If $g_sLocalFileName = "" Then $g_sLocalFileName = $aSplitRemoteFileFullPath[$i]
		_DebugOut("OK: Download wird gestartet...")
		_DebugOut("From: '" & $g_sRemoteCurrentPath & $aSplitRemoteFileFullPath[$i] & "'" & @CRLF & _
				  "  To: '" & $g_sLocalPathName & "\" & $g_sLocalFileName & "'")

		; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		; Download still und leise im Hintergrund.
		;Local $iDlStatus = _FTP_FileGet($g_hFTPConnect, $g_sRemoteCurrentPath & $aSplitRemoteFileFullPath[$i], $g_sLocalPathName & "\" & $g_sLocalFileName, True)	; do not overwrite existing (default = False).
		; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

		; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		; Download mit ProgressBar - ESC = Abbruch
		;Local $iDlStatus = _ProgressDownload($g_sLocalPathName & "\" & $g_sLocalFileName, $g_sRemoteCurrentPath & $aSplitRemoteFileFullPath[$i])
		; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

		; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		; Download mit GUI und ProgressBar - Cancel-Button.
		Local $iDlStatus = _ProgressDownloadGUI($g_sLocalPathName & "\" & $g_sLocalFileName, $g_sRemoteCurrentPath & $aSplitRemoteFileFullPath[$i])
		; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

		; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		; ODER... viel eleganter und schöner... mit https://autoit.de/index.php/Thread/45697-DownloadWithProgress/
		; UDF downloaden und am Anfang des Quelltextes das Include auskommentieren...
		; #include '_DownloadWithProgress.au3'
		;
		; Hier muss für den Download allerdings die komplette URL angegeben werden... und die Datei kann auch erst im Nachhinein umbenannt werden.
		;
		; Local $sURL = $g_sServer & $g_sRemoteCurrentPath & $aSplitRemoteFileFullPath[$i]
		; If StringLeft($sURL, 6) <> "ftp://" Then $sURL = "ftp://" & $sURL
		; _DownloadWithProgress($sURL, $g_sLocalPathName, 1031, 'AutoIt-Download-Tool', -1, -1)	; 1031 = deutsch
		; $iError = @error
		; If Not $iError Then $iDlStatus = 1
		; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

		If $iDlStatus = 1 Then
			_DebugOut("OK - Download wurde erfoglreich beendet.")
		Else
			$iError = @error
			__DebugError("Während des Downloads ist ein Fehler aufgetreten. Datei bereits vorhanden?", $iError, 0)
		EndIf
	Else
		__DebugError("Lokaler Pfad " & $g_sLocalPathName & " existiert nicht!", 0 , 0)
	EndIf

EndFunc  ;==>_main

Func _Open_FTP_Session()
	_DebugOut("Open FTP Session...")
	$g_hFTPOpen = _FTP_Open('MyFTP Control')
	If $g_hFTPOpen = 0 Then
		__DebugError("_FTP_Open", @error, @extended)
		_Exit(1)
	Else
		_DebugOut("OK - _FTP_Open" & @CRLF & "   - $g_hFTPOpen = " & $g_hFTPOpen)
	EndIf
EndFunc  ;==>_Open_FTP_Session

Func _SetInternetOptions()
	_DebugOut(@CRLF & "Set InternetSetOptions (CONNECT_TIMEOUT & RECEIVE_TIMEOUT)")
	$sMessage = __InternetSetOptionsW()
	If @error Then
		__DebugError($sMessage, @error, @extended)
		_Exit(2)
	EndIf
	_DebugOut("OK - InternetOptions" & @CRLF & _
		"   - CONNECT_TIMEOUT = " & "0x" & Hex($g_iValue_CONNECT_TIMEOUT, 8) & @CRLF & _
		"   - RECEIVE_TIMEOUT = " & "0x" & Hex($g_iValue_RECEIVE_TIMEOUT, 8))
EndFunc  ;==>_SetInternetOptions

Func _Check_InternetOptions()
	_DebugOut(@CRLF & "Check InternetOptions")
	Local $tBuffer = __InternetQueryOptionW($g_hFTPOpen, $g_iINTERNET_OPTION_CONNECT_TIMEOUT, 4)
	If @error Then
		__DebugError("InternetQueryOption CONNECT_TIMEOUT", @error, @extended)
	Else
		;$tBufferLength = @extended
		Local $iInternetQueryOption_CONNECT_TIMEOUT = '0x' & Hex(_WinAPI_SwapDWord(String(DllStructGetData($tBuffer, 1))), 8)
		If $iInternetQueryOption_CONNECT_TIMEOUT = '0x' & Hex($g_iValue_CONNECT_TIMEOUT, 8) Then
			_DebugOut("OK - CONNECT_TIMEOUT Query = Value " & $iInternetQueryOption_CONNECT_TIMEOUT & " = " & '0x' & Hex($g_iValue_CONNECT_TIMEOUT, 8))
		Else
			_DebugOut("FAIL - CONNECT_TIMEOUT Query <> Value " & $iInternetQueryOption_CONNECT_TIMEOUT & " <> " & '0x' & Hex($g_iValue_CONNECT_TIMEOUT, 8))
		EndIf
	EndIf

	Local $tBuffer = __InternetQueryOptionW($g_hFTPOpen, $g_iINTERNET_OPTION_RECEIVE_TIMEOUT, 4)
	If @error Then
		__DebugError("InternetQueryOption RECEIVE_TIMEOUT", @error, @extended)
	Else
		;$tBufferLength = @extended
		Local $iInternetQueryOption_RECEIVE_TIMEOUT = '0x' & Hex(_WinAPI_SwapDWord(String(DllStructGetData($tBuffer, 1))), 8)
		If $iInternetQueryOption_RECEIVE_TIMEOUT = '0x' & Hex($g_iValue_RECEIVE_TIMEOUT, 8) Then
			_DebugOut("OK - RECEIVE_TIMEOUT Query = Value " & $iInternetQueryOption_RECEIVE_TIMEOUT & " = " & '0x' & Hex($g_iValue_RECEIVE_TIMEOUT, 8))
		Else
			_DebugOut("FAIL - RECEIVE_TIMEOUT Query <> Value " &  $iInternetQueryOption_RECEIVE_TIMEOUT & " <> " & '0x' & Hex($g_iValue_RECEIVE_TIMEOUT, 8))
		EndIf
	EndIf
EndFunc  ;==>_Check_InternetOptions

Func _Setup_FTPStatusCallbackHandler()
	_DebugOut(@CRLF & "Setup FTPStatusCallbackHandler")
	$g_pCallback = _FTP_SetStatusCallback($g_hFTPOpen, 'FTPStatusCallbackHandler')
	If @error Then
		__DebugError("Setup FTPStatusCallbackHandler", @error, @extended)
		_Exit(3)
	Else
		_DebugOut("OK - FTPStatusCallbackHandler = " & $g_pCallback)
	EndIf
EndFunc  ;==>_Setup_FTPStatusCallbackHandler

Func _Connect_FTP_Server()
	For $c = 1 To $g_iAttempts
		_DebugOut(@CRLF & "Connect to Server... " & $g_sServer)
		$g_hFTPConnect = _FTP_Connect($g_hFTPOpen, $g_sServer, $g_sUsername, $g_sPass, 0, $g_iFTP_PORT, $INTERNET_SERVICE_FTP, 0, $g_pCallback)
		If $g_hFTPConnect = 0 Then
			$iError = @error
			$iExtended = @extended
			If $iExtended = $g_ERROR_INTERNET_NAME_NOT_RESOLVED Then _DebugOut("The server name could not be resolved.")
			__DebugError("_FTP_Connect - connection attempt = " & $c & "/" & $g_iAttempts, @error, @extended)
			If $c = $g_iAttempts Then _Exit(4)
		Else
			_DebugOut("OK - _FTP_Connect" & @CRLF & "   - $g_hFTPConnect = " & $g_hFTPConnect & @CRLF & "   - Benötigte Verbindungsversuche = " & $c)
			ExitLoop
		EndIf
	Next
EndFunc  ;==>_Connect_FTP_Server

Func _Get_FTP_CurrentDir()
	_DebugOut(@CRLF & "Get Current Directory on an FTP server")
	$g_sCurrentDir = _FTP_DirGetCurrent($g_hFTPConnect)
	If $g_sCurrentDir = "0" Then	; die "" sind wichtig...
		__DebugError("_FTP_DirGetCurrent", @error, @extended)
		_Exit(5)
	Else
		_DebugOut("OK - _FTP_DirGetCurrent: " & $g_sCurrentDir)
	EndIf
EndFunc  ;==>_Get_FTP_CurrentDir

Func _Get_FTP_DirListEx($iReturnType = 0)
	_DebugOut(@CRLF & "Get Filenames and filesizes of current remote directory")
	$g_aFTP_ListEx = _FTP_ListToArrayEx($g_hFTPConnect, $iReturnType)	; $iReturnType 0 = Both Files and Directories, 1 = Directories, 2 = Files.
	If $g_aFTP_ListEx[0][0] = 0 Then
		__DebugError("_FTP_ListToArrayEx", @error, @extended)
		_Exit(6)
	Else
		_DebugOut("OK - _FTP_ListToArrayEx - Einträge: " & $g_aFTP_ListEx[0][0])
		For $i = 1 To $g_aFTP_ListEx[0][0]
			_DebugOut(StringFormat("   - %-26s", $g_aFTP_ListEx[$i][0]) & StringFormat("%26s", $g_aFTP_ListEx[$i][1]))
		Next
	EndIf
EndFunc  ;==>_Get_FTP_DirListEx

Func _Set_FTP_CurrentDir($sCurrentDir = "pub")
	_DebugOut(@CRLF & "Set Current Directory on an FTP server...")
	Local $sNewCurrentDir = _FTP_DirSetCurrent($g_hFTPConnect, $sCurrentDir)
	If $sNewCurrentDir = 0 Then
		__DebugError("_FTP_DirSetCurrent = '" & $sCurrentDir & "'", @error, @extended)
		_Exit(7)
	Else
		_DebugOut("OK - _FTP_DirSetCurrent = '" & $sCurrentDir & "'")
		$g_sCurrentDir = $sCurrentDir
	EndIf
EndFunc  ;==>_Set_FTP_CurrentDir

Func _ProgressDownload($sLocalFile, $sRemoteFile)
    Local $sFunctionToCall = "_UpdateProgress"
    ProgressOn("Download Progress", $sRemoteFile)
    Local $iDlStatus = _FTP_ProgressDownload($g_hFTPConnect, $sLocalFile, $sRemoteFile, $sFunctionToCall)
	$iError = @error
    ProgressOff()
	If $iError Then Return SetError($iError)

	Return $iDlStatus
EndFunc  ;==>_ProgressDownload

Func _UpdateProgress($iPercent)
    ProgressSet($iPercent, Int($iPercent) & "%")
    If _IsPressed("1B") Then Return 0 ; Abort on ESC
    Return 1 ; 1 to continue Download
EndFunc  ;==>_UpdateProgress

Func _ProgressDownloadGUI($sLocalFile, $sRemoteFile)
    ; create GUI
	; GUICreate ( "title" [, width [, height [, left = -1 [, top = -1 [, style = -1 [, exStyle = -1 [, parent = 0]]]]]]] )
    $g_hMyGUI = GUICreate("MyFTP Control download Progressbar", 480, 100, @DesktopWidth/2, @DesktopHeight/2)
    GUICtrlCreateLabel($sRemoteFile, 10, 10)

	;Local $aPos = WinGetPos($hMyGUI)
	; GUICtrlCreateProgress ( left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
    $g_idProgressBarCtrl = GUICtrlCreateProgress(10, 30, 460, 20, $PBS_SMOOTH)
    GUICtrlSetColor(-1, 32250); not working with Windows XP Style

	; GUICtrlCreateLabel ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
	$g_LaProz = GUICtrlCreateLabel(StringRight("  0%", 4), 10, 65, 80, 20, -1 ,$WS_EX_TRANSPARENT)
	GUICtrlSetFont(-1, 12.0, $FW_EXTRABOLD, 0, "Courier New")

	; GUICtrlCreateButton ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
    $g_idBtn_Cancel = GUICtrlCreateButton("Cancel", 400, 70, 70, 20)

    GUISetState(@SW_SHOW)

    Local $sFunctionToCall = _UpdateGUIProgressBar	; darf nicht, wie in der AutoIt-Hilfe beschrieben, in "" oder '' stehen!
	If Not IsFunc($sFunctionToCall) Then ConsoleWrite("@@ Debug line" & @TAB & @ScriptLineNumber & "   var: $hFunctionCall --> " & VarGetType($sFunctionToCall) & @LF & "!@ " & @TAB & "#Error: " & @error & @TAB & "#Extended: " & @extended & @LF)
    Local $iDlStatus = _FTP_ProgressDownload($g_hFTPConnect, $sLocalFile, $sRemoteFile, $sFunctionToCall)
	If @error Then Return SetError(@error)

	Return $iDlStatus
EndFunc  ;==>_ProgressDownloadGUI

Func _UpdateGUIProgressBar($iPercent)
    GUICtrlSetData($g_idProgressBarCtrl, $iPercent)
	Local $sText = StringRight("  " & Int($iPercent) & "%", 4)
	ControlSetText($g_hMyGUI, "", $g_LaProz, $sText, 1)
	Sleep(50)
	If $iPercent >= 100 Then
		Sleep(1000)
		GUIDelete()
	EndIf
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit -1 ; _FTP_DownloadProgress Aborts with -1, so you can exit your app afterwards
        Case $g_idBtn_Cancel
            Exit -2 ; Just Cancel, without special Return value
    EndSwitch
    Return 1 ; Otherwise continue Download
EndFunc  ;==>_UpdateGUIProgressBar

Func FTPStatusCallbackHandler($hInternet, $iContext, $iInternetStatus, $pStatusInformation, $iStatusInformationLength)
	#forceref $hInternet, $iContext
	If $iInternetStatus = $INTERNET_STATUS_REQUEST_SENT Or $iInternetStatus = $INTERNET_STATUS_RESPONSE_RECEIVED Then
		Local $iBytesRead
		Local $tSize = DllStructCreate('dword')
		_WinAPI_ReadProcessMemory(_WinAPI_GetCurrentProcess(), $pStatusInformation, DllStructGetPtr($tSize), $iStatusInformationLength, $iBytesRead)
		_DebugOut(_FTP_DecodeInternetStatus($iInternetStatus) & ' | Size = ' & DllStructGetData($tSize, 1) & ' Bytes    Bytes read = ' & $iBytesRead)
	Else
		_DebugOut(_FTP_DecodeInternetStatus($iInternetStatus))
	EndIf
EndFunc  ;==>FTPStatusCallbackHandler

Func __InternetSetOptionsW()
	; BOOL InternetSetOption(
	; _In_ HINTERNET hInternet,
	; _In_ DWORD     dwOption,
	; _In_ LPVOID    lpBuffer,
	; _In_ DWORD     dwBufferLength
	; );

	; Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError.
	Local $time = DllStructCreate("long")
	DllStructSetData($time, 1, $g_iValue_CONNECT_TIMEOUT)
	Local $ai_IOCT = DllCall($g_hWININET, _
		'int', 'InternetSetOptionW', _
		'hwnd', $g_hFTPOpen, _
		'dword', $g_iINTERNET_OPTION_CONNECT_TIMEOUT, _
		"ptr", DllStructGetPtr($time), _
		"dword", DllStructGetSize($time) _
	)
	If @error Or $ai_IOCT[0] = False Then
		DllClose($g_hWININET)
		Return SetError(False, 1, "CONNECT_TIMEOUT")
	EndIf

	DllStructSetData($time, 1, $g_iValue_RECEIVE_TIMEOUT)
	Local $ai_IORT = DllCall($g_hWININET, _
		'int', 'InternetSetOptionW', _
		'hwnd', $g_hFTPOpen, _
		'dword', $g_iINTERNET_OPTION_RECEIVE_TIMEOUT, _
		"ptr", DllStructGetPtr($time), _
		"dword", DllStructGetSize($time) _
	)
	If @error Or $ai_IORT[0] = False Then
		DllClose($g_hWININET)
		Return SetError(False, 2, "RECEIVE_TIMEOUT")
	EndIf

	Return True
EndFunc  ;==>__InternetSetOptionsW

Func __InternetQueryOptionW($hInternet, $iOption, $iBufferSize = 2048)
	; BOOL InternetQueryOption(
	; _In_    HINTERNET hInternet,
	; _In_    DWORD     dwOption,
	; _Out_   LPVOID    lpBuffer,
	; _Inout_ LPDWORD   lpdwBufferLength
	; );

	; Set data/structures up
	Local $tBufferLength = DllStructCreate("dword")
	DllStructSetData($tBufferLength, 1, $iBufferSize)

	Local $tBuffer = DllStructCreate("byte[" & $iBufferSize & "]")

	; Make DLL call
	Local $avResult = DllCall($g_hWININET, _
		"int", "InternetQueryOptionW", _
		"ptr",   $hInternet, _
		"dword", $iOption, _
		"ptr",   DllStructGetPtr($tBuffer), _
		"ptr",   DllStructGetPtr($tBufferLength) _
	)

	; Return response
	If @error Then Return SetError(1, 0, "")
	If Not $avResult[0] Then Return SetError(2, DllStructGetData($tBufferLength, 1), "")
	Return SetError(0, DllStructGetData($tBufferLength, 1), $tBuffer)
EndFunc  ;==>__InternetQueryOptionW

Func __DebugError($sFTP_Func, $iError, $iExtended)
	Local $sMessage = ""
	_FTP_GetLastResponseInfo($iError, $sMessage)
	_DebugOut(@CRLF & "FAIL - " & $sFTP_Func)
	_DebugOut("@error    = " & $iError)
	_DebugOut("@extended = " & $iExtended)
	_DebugOut($sMessage)
EndFunc  ;==>__DebugError

Func __ModifyDebugWin()	; Debug - Fenster verschieben, sowie Farbe, Schriftart und Größe anpassen
	Local $hDebugOut = WinGetHandle($__g_sReportTitle_Debug) ; "SlowFTP _SlowFTP"
	If Not @error Then
		GUISetBkColor(0x292929, $hDebugOut)
		Local $hDebugWinEdit = ControlGetHandle($hDebugOut, "", "[CLASS:Edit; INSTANCE:1]")
		If @error Then
			ConsoleWrite("$hDebugWinEdit nicht gefunden." & @CRLF)
		Else
			Local $idDebugWinEdit = _WinAPI_GetDlgCtrlID($hDebugWinEdit)	; hWnd --> controlID
			If $idDebugWinEdit <> 0 Then
				GUICtrlSetColor($idDebugWinEdit, 0x9B9B9B)
				GUICtrlSetBkColor($idDebugWinEdit, 0x292929)	; 0xFFFFFF
				GUICtrlSetFont($idDebugWinEdit, 9.5, 400, 0, "Courier New", 0)
			EndIf
		EndIf
		WinMove($hDebugOut, "", Int(@DesktopWidth * 0.6), Int(@DesktopHeight * 0.2), Int(@DesktopWidth * 0.4), Int(@DesktopHeight * 0.8), 5)
		GUISetBkColor(0xB22222, $hDebugOut)
	Else
		Return SetError(1, 0, "_DebugSetup() nicht gestartet?")
	EndIf

	Return 1
EndFunc  ;==>__ModifyDebugWin

Func _Exit($iError = 0)
	If $g_hFTPConnect <> -1 Then _FTP_Close($g_hFTPConnect)
	If $g_hFTPOpen    <> -1 Then _FTP_Close($g_hFTPOpen)
	If $g_hWININET    <> -1 Then DllClose($g_hWININET)
	Exit $iError
EndFunc  ;==>_Exit
