Sign in to follow this  
Followers 0
Wombat

A little help with FTP please

2 posts in this topic

#1 ·  Posted (edited)

I'm making a program that will use a listbox(or listview) that will display the contents of an FTP site. I have figured out the connection, What I need to be able to do is list the files and folders and be able to navigate in the directories and what not. All I need help with is how to list the files and folders just as this script does in the top-right box does:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=main.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/SOI /sci 1
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Icon_Add=Back.ico
#AutoIt3Wrapper_Res_Icon_Add=Up.ico
#AutoIt3Wrapper_Res_Icon_Add=Down.ico
#Obfuscator_Ignore_Funcs=_Receiver, _Transfer, _FTP_StatusHandler, _CPU_IdleClock_Update, _GUICtrl_SetOnHover, _ListSetFocus
#include <ComboConstants.au3>
#include <GuiRichEdit.au3>
#include <StructureConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
#include <array.au3>
#include <file.au3>
#include <GUIListView.au3>
#include <FTPEx.au3>
#include <GuiMenu.au3>
#include <Guiedit.au3>
#include <Misc.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <Timers.au3>
#include <String.au3>
#include <Date.au3>
#include <Constants.au3>
#include <GuiImageList.au3>
#include "Includes\MouseHoverSetFocus.au3"
#include "Includes\Messages.au3"

Opt("MustDeclareVars", 1)
Opt("TrayAutoPause", 0)

If _Singleton("FTP Explorer V2", 1) = 0 Then
    MsgBox(0, "Warning", "An occurence of FTP Explorer V2 is already running")
    Exit
EndIf

If @Compiled Then
    Global $g_sWorker = _TempFile(@ScriptDir, "FTPWorker", ".a3x", 12)
    FileInstall('F:\AutoIt\FTP Explorer Project\Main\Compile\FTP Worker.a3x', $g_sWorker, 1)
    FileSetAttrib($g_sWorker, 'H')
Else
    Global $g_sWorker = @ScriptDir & '\FTP Worker.au3'
EndIf

_StartCommunications()
OnAutoItExitRegister('_ExitTime')

#region Global Vars, Constants and Dlls...............................

;Dlls
Global Enum $g_hPSAPI, $g_hUser32, $g_hKernel32, $g_hShell32, $DllMaX
Global $aDll[$DllMaX] = [DllOpen("psapi.dll"), DllOpen("user32.dll"), DllOpen('kernel32.dll'), DllOpen('shell32.dll')]

;Constants
Global Const $cRed = '255', $cGreen = '45824', $cBlue = '16711680', $cGray = '8421504';colors
Global Const $cPink = '16711935', $cYellow = '65535', $cTeal = '16776960', $cPurp = '16711830';colors
Global Const $FOLDER_ICON_INDEX = _GUIImageList_GetFileIconIndex(@SystemDir, 0, 1)
Global Const $INTERNET_OPTION_RECEIVE_TIMEOUT = 6

;FTP Connection Status Vars
Global Enum $giUploading, $giDownloading, $giIdle, $giFinished; If you change these you must change the ones in FTP_Worker to be the same
Global $FTP_State = $giIdle, $gbFTP_Connected = False, $gbFTP_NOReconnet = False
Global $ghFTPOpen, $ghFTPConnect, $gsServer_Name, $gsServer_IP, $gaConnectionInfo[4], $ghFTPCallBack, $gaQueue[1]
Global $CPU, $sComboFTP, $sComboLocal, $gsLocalCurrent
Global $gaLocalHistory[20], $gaFTPHistory[20]

;Timers
Global Enum $g_tCPU, $g_tTransfer, $g_tIdleClock, $g_bIdleClock, $MaXTimers
Global $aTimers[$MaXTimers]
$aTimers[$g_bIdleClock] = False

;FTP Connect GUI vars
Global Enum $g_sIP, $g_iPort, $g_sUser, $g_sPass, $g_hIP, $g_sINIHistory, $MaxConnectGUI
Global $aConnectGUI[$MaxConnectGUI]
$aConnectGUI[$g_sINIHistory] = @ScriptDir & '\History.ini'

#endregion Global Vars, Constants and Dlls...............................
#region GUI...........................................................

Global Enum $g_bActive, $g_sTitle, $g_iWidth, $g_iHeight, $g_hGUI, $g_FileMenu, $g_FileItem1, $g_FileItem2, $g_FileItem3, $g_HelpMenu, $g_HelpItem1, $g_HelpItem2, $g_LocalList, _
        $g_FTPList, $g_QueueList, $g_StatusList, $g_lbFTPCount, $g_lbLocalCount, $g_cbFTP, $g_cbLocal, $g_bFTPBack, $g_bLocalBack, $g_hStatusBar, $g_hProgressBar, $g_hImageList, _
        $g_iUpICO, $g_iDownICO, $g_iParentICO, $MaxGUI
Global $aGUI[$MaxGUI]

$aGUI[$g_sTitle] = "Explorer V2"
$aGUI[$g_iWidth] = 880
$aGUI[$g_iHeight] = 541
$aGUI[$g_hGUI] = GUICreate($aGUI[$g_sTitle], $aGUI[$g_iWidth], $aGUI[$g_iHeight])
GUISetStyle(BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS), -1, $aGUI[$g_hGUI])
$aGUI[$g_FileMenu] = GUICtrlCreateMenu("&File")
$aGUI[$g_FileItem1] = GUICtrlCreateMenuItem("Connect", $aGUI[$g_FileMenu])
$aGUI[$g_FileItem2] = GUICtrlCreateMenuItem("Disconnect", $aGUI[$g_FileMenu])
$aGUI[$g_FileItem3] = GUICtrlCreateMenuItem("Exit", $aGUI[$g_FileMenu])
$aGUI[$g_HelpMenu] = GUICtrlCreateMenu("&Help")
$aGUI[$g_HelpItem1] = GUICtrlCreateMenuItem("How To Use", $aGUI[$g_HelpMenu])
$aGUI[$g_HelpItem2] = GUICtrlCreateMenuItem("About", $aGUI[$g_HelpMenu])
$aGUI[$g_LocalList] = GUICtrlCreateListView("File", 4, 22, 429, 250, $LVS_SHOWSELALWAYS)
$aGUI[$g_FTPList] = GUICtrlCreateListView("File", 444, 22, 429, 250, $LVS_SHOWSELALWAYS)
$aGUI[$g_QueueList] = GUICtrlCreateListView("Name|Target", 4, 291, 429, 201, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($aGUI[$g_QueueList], BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
$aGUI[$g_StatusList] = _GUICtrlRichEdit_Create($aGUI[$g_hGUI], "", 444, 291, 429, 201, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_READONLY))
_RichEdit_AppendColor('FTP Explorer V2', '45824', True)
$aGUI[$g_lbFTPCount] = GUICtrlCreateLabel("", 444, 272, 428, 17, BitOR($SS_CENTER, $SS_CENTERIMAGE))
$aGUI[$g_lbLocalCount] = GUICtrlCreateLabel("", 5, 272, 428, 17, BitOR($SS_CENTER, $SS_CENTERIMAGE))
$aGUI[$g_cbFTP] = GUICtrlCreateCombo("", 470, 0, 403, 25)
$aGUI[$g_bFTPBack] = GUICtrlCreateButton("Button1", 444, 0, 25, 21, $BS_ICON)
GUICtrlSetTip(-1, 'Navigate Back')
$aGUI[$g_cbLocal] = GUICtrlCreateCombo("", 30, 0, 403, 25)
$aGUI[$g_bLocalBack] = GUICtrlCreateButton("Button1", 4, 0, 25, 21, $BS_ICON)
GUICtrlSetTip(-1, 'Navigate Back')
_Statusbar(1)
Global $GUI_AccelTable[1][2] = [["!+h", $aGUI[$g_FileItem3]]]
GUISetAccelerators($GUI_AccelTable)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")

If @Compiled Then
    GUICtrlSetImage($aGUI[$g_bFTPBack], @ScriptFullPath, -5, 0)
    GUICtrlSetImage($aGUI[$g_bLocalBack], @ScriptFullPath, -5, 0)
    $aGUI[$g_hImageList] = _GUIImageList_GetSystemImageList()
    $aGUI[$g_iDownICO] = _GUIImageList_AddIcon($aGUI[$g_hImageList], @ScriptFullPath, 6) + 1
    $aGUI[$g_iUpICO] = _GUIImageList_AddIcon($aGUI[$g_hImageList], @ScriptFullPath, 5) + 1
Else
    GUICtrlSetImage($aGUI[$g_bLocalBack], @ScriptDir & '\Icons\back.ico', 0, 0)
    GUICtrlSetImage($aGUI[$g_bFTPBack], @ScriptDir & '\Icons\back.ico', 0, 0)
    $aGUI[$g_hImageList] = _GUIImageList_GetSystemImageList()
    $aGUI[$g_iDownICO] = _GUIImageList_AddIcon($aGUI[$g_hImageList], @ScriptDir & '\Icons\Down.ico') + 1
    $aGUI[$g_iUpICO] = _GUIImageList_AddIcon($aGUI[$g_hImageList], @ScriptDir & '\Icons\Up.ico') + 1
EndIf

_GUICtrlListView_SetImageList($aGUI[$g_LocalList], $aGUI[$g_hImageList], 1)
_GUICtrlListView_SetImageList($aGUI[$g_FTPList], $aGUI[$g_hImageList], 1)
_GUICtrlListView_SetImageList($aGUI[$g_QueueList], $aGUI[$g_hImageList], 1)
_GUICtrlListView_SetImageList($aGUI[$g_QueueList], $aGUI[$g_hImageList], 2)
_GUICtrlListView_SetColumnWidth($aGUI[$g_QueueList], 0, 217)
_GUICtrlListView_SetColumnWidth($aGUI[$g_QueueList], 1, 208)
_GUICtrlRichEdit_SetLimitOnText($aGUI[$g_StatusList], 100000)

_MouseHover_SetFocus($aGUI[$g_QueueList])
_MouseHover_SetFocus($aGUI[$g_FTPList])
_MouseHover_SetFocus($aGUI[$g_LocalList])
_MouseHover_SetFocus($aGUI[$g_StatusList])
_MouseHover_Enable()

#endregion GUI...........................................................

#region Control Handles...............................................

Global Enum $g_hQueuelist, $g_hLocalList, $g_hFTPList, $g_hLocalCombo, $g_hFTPCombo, $g_hFTPListHeader, $g_hLocalListHeader, $MaxHandles
Global $aHandles[$MaxHandles]

$aHandles[$g_hQueuelist] = GUICtrlGetHandle($aGUI[$g_QueueList])
$aHandles[$g_hLocalList] = GUICtrlGetHandle($aGUI[$g_LocalList])
$aHandles[$g_hFTPList] = GUICtrlGetHandle($aGUI[$g_FTPList])
$aHandles[$g_hLocalCombo] = GUICtrlGetHandle($aGUI[$g_cbLocal])
$aHandles[$g_hFTPCombo] = GUICtrlGetHandle($aGUI[$g_cbFTP])
$aHandles[$g_hFTPListHeader] = HWnd(_GUICtrlListView_GetHeader($aHandles[$g_hFTPList]))
$aHandles[$g_hLocalListHeader] = HWnd(_GUICtrlListView_GetHeader($aHandles[$g_hLocalList]))

#endregion Control Handles...............................................
#region Startup Initiations...........................................
_Check_INI_File()
_Columns($aHandles[$g_hFTPList], 'FTPColumns', True)
_Columns($aHandles[$g_hLocalList], 'LocalColumns', True)
$aTimers[$g_tCPU] = _Timer_SetTimer($aGUI[$g_hGUI], 1000, "_CPU_IdleClock_Update")
_MyComputer()
GUISetState(@SW_SHOW, $aGUI[$g_hGUI])
_FTP_Connect_GUI()
If $aDll[$g_hPSAPI] <> -1 Then AdlibRegister('_ReduceMemory', 60000)
_ReduceMemory()
;~ Sleep(2000)
#endregion Startup Initiations...........................................
#region Main Loop.....................................................
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $aGUI[$g_FileItem3]
            If $FTP_State <> $giIdle Then
                Local $bMouseHover = _MouseHover_Disable()
                If MsgBox(36 + 262144, 'Transfer in Progress!', 'Are you sure you want to abort current transfer and quit?') = 7 Then
                    If $bMouseHover Then _MouseHover_Enable()
                    ContinueLoop
                Else
                    IniWrite($aConnectGUI[$g_sINIHistory], 'Abort', 'Abort', 3); 3 means exit
                EndIf
            Else
                _MsgSend('Worker', 3 & ';');tell worker to disconnect and exit
            EndIf
            _FTP_Disconnect()
            Do
                Sleep(100)
            Until Not _IsReceiver('Worker')
            Exit
        Case $GUI_EVENT_RESTORE, $GUI_EVENT_MAXIMIZE
            If $FTP_State <> $giIdle Then
                Local $FileNameLen
                If ($aGUI[$g_iWidth] / 2) > 480 Then
                    $FileNameLen = ($aGUI[$g_iWidth] / 2)
                Else
                    $FileNameLen = $aGUI[$g_iWidth] - 580 ; ;[75, ?,  80,  80,  80, 140, 200]
                EndIf
                Local $StatusBar_PartsWidth[7] = [75, $FileNameLen, $FileNameLen + 80, $FileNameLen + 160, $FileNameLen + 240, $FileNameLen + 380, -1]
                _GUICtrlStatusBar_SetParts($aGUI[$g_hStatusBar], $StatusBar_PartsWidth)
                _GUICtrlStatusBar_EmbedControl($aGUI[$g_hStatusBar], 6, GUICtrlGetHandle($aGUI[$g_hProgressBar]), 4)
            Else
                Local $StatusBar_PartsWidth[4] = [200, ($aGUI[$g_iWidth] / 2), ($aGUI[$g_iWidth] - 80), -1]
                _GUICtrlStatusBar_SetParts($aGUI[$g_hStatusBar], $StatusBar_PartsWidth)
            EndIf
            _Resize_Rich_Edit()
        Case $aGUI[$g_FileItem1] ;connect
            _FTP_Connect_GUI()
        Case $aGUI[$g_FileItem2] ;disconnect
            If $FTP_State <> $giIdle Then
                Local $bMouseHover = _MouseHover_Disable()
                If MsgBox(36 + 262144, 'Transfer in Progress!', 'Are you sure you want to abort current transfer and disconnet?') = 7 Then
                    If $bMouseHover Then _MouseHover_Enable()
                    ContinueLoop
                Else
;~                  $gbFTP_NOReconnet = True
                    IniWrite($aConnectGUI[$g_sINIHistory], 'Abort', 'Abort', 2);This will make the call to _FTP_Disconnect
                EndIf
                If $bMouseHover Then _MouseHover_Enable()
            Else
                _MsgSend('Worker', 2 & ';')
                _FTP_Disconnect()
            EndIf
            GUICtrlSetState($aGUI[$g_FileItem1], $GUI_ENABLE)
        Case $aGUI[$g_bFTPBack]
            _FTPBack()
        Case $aGUI[$g_bLocalBack]
            _LocalBack()
;~      Case $aGUI[$g_HelpItem1]
        Case $aGUI[$g_HelpItem2]
            _About("About Info", "FTP Explorer", "Copyright © " & @YEAR & " Brian J Christy. All rights reserved.", "v2.2", "", "http://www.autoitscript.com", _
                    'Contact Me', "mailto:FreeFTPExplorer@gmail.com", "Written with AutoIT", "http://www.autoitscript.com/", @AutoItExe, 0x0000FF, 0xFFFFFF, -1, -1, -1, -1, $aGUI[$g_hGUI])
    EndSwitch
WEnd
#endregion Main Loop.....................................................
#region Transfer and Queue Functions..................................
Func _Transfer($hWnd, $Msg, $iIDTimer, $dwTime)

    If $FTP_State = $giUploading Or $FTP_State = $giDownloading Then Return

    If $FTP_State = $giFinished Then ; Set by FTP worker
        _ArrayDelete($gaQueue, 1)
        _GUICtrlListView_DeleteItem($aHandles[$g_hQueuelist], 0)
    EndIf

    Static $Up = False, $down = False
    If (UBound($gaQueue) - 1) > 0 Then
        Local $aSplit = StringSplit($gaQueue[1], ';')
    Else
        $FTP_State = $giIdle
        _Timer_KillTimer($aGUI[$g_hGUI], $aTimers[$g_tTransfer])
        If $Up Then _FtpRefresh($INTERNET_FLAG_RELOAD)
        If $down Then _LocalGo($gsLocalCurrent)
        $Up = False
        $down = False
        _Statusbar(2)
        Return
    EndIf

    Select
        Case $aSplit[1] = 'upload'
            _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], 'Uploading', 0)
            If $aSplit[2] = 'DIR' Then
                _MsgSend('Worker', 6 & ';' & $aSplit[3] & $aSplit[4] & ';' & $aSplit[5] & $aSplit[4])
            Else
                _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], $aSplit[4], 1)
                _MsgSend('Worker', 4 & ';' & $aSplit[3] & ';' & $aSplit[4] & ';' & $aSplit[5])
            EndIf
            $Up = True
        Case $aSplit[1] = 'download'
            _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], 'Downloading', 0)
            If $aSplit[2] = 'DIR' Then
                _MsgSend('Worker', 7 & ';' & $aSplit[5] & ';' & $aSplit[4] & ';' & $aSplit[3])
            Else
                _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], $aSplit[4], 1)
                _MsgSend('Worker', 5 & ';' & $aSplit[3] & ';' & $aSplit[4] & ';' & $aSplit[5] & ';' & $aSplit[6])
            EndIf
            $down = True
    EndSelect

EndFunc   ;==>_Transfer
Func _QueueItems($hList)

    Local $aSelected, $i, $sFileName, $sItem, $sQueueItem
    Local $iIcon, $sType, $hOtherList, $iDup, $tInfo, $sSource, $sDest

    If $hList = $aHandles[$g_hFTPList] Then
        $hOtherList = $aHandles[$g_hLocalList]
    Else
        $hOtherList = $aHandles[$g_hFTPList]
    EndIf

    $tInfo = DllStructCreate($tagLVFINDINFO)
    DllStructSetData($tInfo, "Flags", $LVFI_STRING)

    Local $sCurrentFTP = StringReplace(_FTP_DirGetCurrent($ghFTPConnect) & '/', '//', '/')
    Local $sCurrentLocal = StringReplace($gsLocalCurrent & '\', '\\', '\')

    Local $iUpDownIcon
    $aSelected = _GUICtrlListView_GetSelectedIndices($hList, True)
    For $i = 1 To $aSelected[0]
        $sFileName = _GUICtrlListView_GetItemText($hList, $aSelected[$i], 0)
        $iIcon = _GUICtrlListView_GetItemImage($hList, $aSelected[$i])
        $iDup = _GUICtrlListView_FindItem($hOtherList, -1, $tInfo, $sFileName)
        If $iDup > 0 Then
            Local $bMouseHover = _MouseHover_Disable()
            If MsgBox(36, 'Confirm Overwrite', $sFileName & ' is already in the location you wish to send it to. Are you sure you want to replace it?') = 7 Then
                If $bMouseHover Then _MouseHover_Enable()
                ContinueLoop
            EndIf
        EndIf
        If $iIcon = $FOLDER_ICON_INDEX Then
            $sType = 'DIR'
        Else
            $sType = 'file'
        EndIf
        If $hList = $aHandles[$g_hFTPList] Then
            $sQueueItem = 'download;' & $sType & ';' & $sCurrentLocal & ';' & $sFileName & ';' & $sCurrentFTP & ';' & _FTP_FileGetSize($ghFTPConnect, $sFileName)
            $sSource = $sCurrentFTP & $sFileName
            $sDest = $sCurrentLocal
            $iUpDownIcon = $aGUI[$g_iDownICO]
        Else
            $sQueueItem = 'upload' & ';' & $sType & ';' & $sCurrentLocal & ';' & $sFileName & ';' & $sCurrentFTP
            $sSource = $sCurrentLocal & $sFileName
            $sDest = $sCurrentFTP
            $iUpDownIcon = $aGUI[$g_iUpICO]
        EndIf
        $sItem = _GUICtrlListView_AddItem($aGUI[$g_QueueList], $sSource, $iIcon)
        _GUICtrlListView_AddSubItem($aGUI[$g_QueueList], $sItem, $sDest, 1)
        _GUICtrlListView_SetItemStateImage($aGUI[$g_QueueList], $sItem, $iUpDownIcon)
        _ArrayAdd($gaQueue, $sQueueItem)
    Next
EndFunc   ;==>_QueueItems
#endregion Transfer and Queue Functions..................................
#region Script Communication Functions................................
Func _StartCommunications()
    _MsgRegister('Boss', '_Receiver')
    Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $g_sWorker & '"')
    Do
        Sleep(100)
    Until _IsReceiver('Worker')
EndFunc   ;==>_StartCommunications
Func _Receiver($Msg)
    Local $aMsg = StringSplit($Msg, ';', 2)
    Switch $aMsg[0]
        Case 1;Set State
            $FTP_State = $aMsg[1]
        Case 2; Update StatusBar transfer values
            Static $Time = 0, $speed = 0, $bytes_transfer = 0

            If $aMsg[4] <> $Time Then
                If $aMsg[4] < 3600 Then;Time
                    _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], "Time (" & StringFormat("%02i:%02i", Int($aMsg[4] / 60), Mod($aMsg[4], 60)) & ")", 3)
                Else
                    Local $iTicks = Mod($aMsg[4], 3600)
                    _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], "Time (" & StringFormat("%02i:%02i:%02i", Int($aMsg[4] / 3600), Int($iTicks / 60), Mod($iTicks, 60)) & ")", 3)
                EndIf
                $aMsg[4] = $Time
            EndIf

            If $aMsg[3] <> $bytes_transfer Then
                _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], $aMsg[3], 5); bytes transferd
                $bytes_transfer = $aMsg[3]
            EndIf
            If $aMsg[2] <> $speed Then
                _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], $aMsg[2], 4);speed
                $aMsg[2] = $speed
            EndIf

            GUICtrlSetData($aGUI[$g_hProgressBar], $aMsg[1])
        Case 3; Update StatusBar filename - used when transfering directorys
            _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], $aMsg[1], 1)
            _RichEdit_AppendColor('Starting Transfer: ', $cBlue)
            _RichEdit_AppendColor($aMsg[1], 0, True)
        Case 4; Transfer of file finshed
            _RichEdit_AppendColor('Transfered: ', $cBlue)
            _RichEdit_AppendColor($aMsg[1] & ' ')
            _RichEdit_AppendColor(_bytes($aMsg[2]) & ' in ' & _Format_Time($aMsg[3]) & ' (' & _Speed($aMsg[2], $aMsg[3]) & ')', $cBlue, True)
        Case 5;console message
            ConsoleWrite('>>>>>>>WORKER MESSAGE: ' & $aMsg[1] & @CRLF)
        Case 6
            _Timer_KillTimer($aGUI[$g_hGUI], $aTimers[$g_tTransfer])
            _RichEdit_AppendColor('Transfer Aborted!', $cRed, True)
            $FTP_State = $giIdle
            Do
                Sleep(100)
            Until Not _IsReceiver('Worker')
            Local $iDelete = False
            If Int($aMsg[2]) = 1 Then
                _FTP_FileDelete($ghFTPConnect, $aMsg[3])
                If Not @error Then $iDelete = True
            Else
                If FileDelete($aMsg[3]) Then $iDelete = True
            EndIf
            If $iDelete Then
                _RichEdit_AppendColor($aMsg[3])
                _RichEdit_AppendColor(' partial file has been deleted.', $cRed, True)
            Else
                _RichEdit_AppendColor($aMsg[3])
                _RichEdit_AppendColor(' partial file removal failed.', $cRed, True)
            EndIf
            If $aMsg[1] <> '3' Then ;disconnet or abort transfer
                Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $g_sWorker & '"')
                Do
                    Sleep(100)
                Until _IsReceiver('Worker')
                If $aMsg[1] = '2' Then _FTP_Disconnect()
            EndIf
            If $aMsg[1] = '1' Then; just abort transfer so reconnect worker
                _MsgSend('Worker', 1 & ';' & $gaConnectionInfo[0] & ';' & $gaConnectionInfo[1] & ';' & $gaConnectionInfo[2] & ';' & $gaConnectionInfo[3])
                _Statusbar(2)
            EndIf
        Case 7
;~          $pMemoryAddress = ptr($aMsg[1])
    EndSwitch
EndFunc   ;==>_Receiver
#endregion Script Communication Functions................................
#region Local Navigation Functions....................................
Func _MyComputer()
    Local $drives, $attributes, $item, $iIndex = 1
    $gsLocalCurrent = 'My Computer'
    _GUICtrlListView_DeleteAllItems($aHandles[$g_hLocalList])
    $drives = DriveGetDrive("ALL")
    Local $Columns = IniReadSection($aConnectGUI[$g_sINIHistory], 'LocalColumns')
    For $i = 1 To 5
        $Columns[$i][1] = Int($Columns[$i][1])
    Next
    For $i = 1 To $drives[0]
        $item = _GUICtrlListView_AddItem($aHandles[$g_hLocalList], DriveGetLabel($drives[$i] & '\') & ' (' & StringUpper($drives[$i]) & ')', _GUIImageList_GetFileIconIndex($drives[$i] & '\'))
;~      $item = _GUICtrlListView_AddItem($aGUI[$g_LocalList], $drives[$i] & '\', _GUIImageList_GetFileIconIndex($drives[$i] & '\'))
        If $Columns[1][1] Then ;size
            _GUICtrlListView_AddSubItem($aGUI[$g_LocalList], $item, 'DIR', $iIndex)
            $iIndex += 1
        EndIf
        If $Columns[2][1] Then $iIndex += 1;Modified
        If $Columns[3][1] Then;Attributes
            $attributes = FileGetAttrib($drives[$i] & '\')
            _GUICtrlListView_AddSubItem($aGUI[$g_LocalList], $item, $attributes, $iIndex)
        EndIf
        $iIndex = 1
    Next
    GUICtrlSetData($aGUI[$g_lbLocalCount], $drives[0] & ' Drives')
    _ComboHistoryAdd($aGUI[$g_cbLocal], $sComboLocal, 'My Computer')
EndFunc   ;==>_MyComputer
Func _LocalDirSwitch($index)
    Local $sChangeDir
    Select
        Case _GUICtrlListView_GetItemText($aGUI[$g_LocalList], $index) = '[..]'
            _LocalParent()
            Return
        Case $gsLocalCurrent = 'My Computer';
            Local $sItem = _GUICtrlListView_GetItemText($aGUI[$g_LocalList], $index)
            $sChangeDir = StringMid($sItem, StringInStr($sItem, '(') + 1, 2) & '\'
        Case Else
            $sChangeDir = StringReplace($gsLocalCurrent & '\' & _GUICtrlListView_GetItemText($aGUI[$g_LocalList], $index), '\\', '\')
            If StringInStr(FileGetAttrib($sChangeDir), 'D') = 0 Then Return
    EndSelect
    _Push_History($gsLocalCurrent, $gaLocalHistory)
    _LocalSetBackTip($gsLocalCurrent)
    _LocalGo($sChangeDir)
EndFunc   ;==>_LocalDirSwitch
Func _LocalParent()
    Local $aDirSplit, $sChangeDir
    $aDirSplit = StringSplit($gsLocalCurrent, '\')
    If $aDirSplit[0] = 2 Then
        If $aDirSplit[2] = '' Then
            $sChangeDir = 'My Computer'
        Else
            $sChangeDir = $aDirSplit[1] & '\'
        EndIf
    Else
        For $i = 1 To $aDirSplit[0] - 1
            $sChangeDir &= $aDirSplit[$i] & '\'
        Next
        $sChangeDir = StringTrimRight($sChangeDir, 1)
    EndIf
    _Push_History($gsLocalCurrent, $gaLocalHistory)
    _LocalSetBackTip($gsLocalCurrent)
    _LocalGo($sChangeDir)
EndFunc   ;==>_LocalParent
Func _LocalGo($sDirectory)
    If $sDirectory = 'My Computer' Then Return _MyComputer()
    Local $item, $iIcon, $iDirs = 0, $iFiles = 0, $iSize = 0
    Local $iIndex, $sSize, $iIndex = 1, $IsDir, $sFile, $attributes, $Time
    _GUICtrlListView_DeleteAllItems($aHandles[$g_hLocalList])
    Local $Columns = IniReadSection($aConnectGUI[$g_sINIHistory], 'LocalColumns')
    For $i = 1 To 5
        $Columns[$i][1] = Int($Columns[$i][1])
    Next
    Local $aList = _FileListToArray_mod($sDirectory)
    _GUICtrlListView_BeginUpdate($aHandles[$g_hLocalList])
    _GUICtrlListView_AddItem($aGUI[$g_LocalList], "[..]", $FOLDER_ICON_INDEX)
    If IsArray($aList) Then
        For $i = 1 To $aList[0]
            $sFile = $sDirectory & '\' & $aList[$i]
            $attributes = FileGetAttrib($sFile)
            If StringInStr($attributes, 'D') > 0 Then
                $IsDir = True
                $sSize = 'DIR'
                $iIcon = $FOLDER_ICON_INDEX
                $iDirs += 1
            Else
                $IsDir = False
                $sSize = FileGetSize($sFile)
                $iSize += $sSize
                $iIcon = _GUIImageList_GetFileIconIndex($aList[$i])
                $iFiles += 1
            EndIf
            $item = _GUICtrlListView_AddItem($aGUI[$g_LocalList], $aList[$i], $iIcon)
            If $Columns[1][1] Then ;size
                If $IsDir Then
                    _GUICtrlListView_AddSubItem($aGUI[$g_LocalList], $item, 'DIR', $iIndex)
                Else
                    _GUICtrlListView_AddSubItem($aGUI[$g_LocalList], $item, _bytes($sSize), $iIndex)
                EndIf
                $iIndex += 1
            EndIf
            If $Columns[2][1] Then;Modified
                $Time = FileGetTime($sFile, 0)
                _GUICtrlListView_AddSubItem($aGUI[$g_LocalList], $item, $Time[0] & '/' & $Time[1] & '/' & $Time[2] & ' ' & $Time[3] & ':' & $Time[4] & ':' & $Time[5], $iIndex)
                $iIndex += 1
            EndIf
            If $Columns[3][1] Then;Attributes
                _GUICtrlListView_AddSubItem($aGUI[$g_LocalList], $item, $attributes, $iIndex)
                $iIndex += 1
            EndIf
            If $Columns[4][1] Then;Creation
                $Time = FileGetTime($sFile, 1)
                _GUICtrlListView_AddSubItem($aGUI[$g_LocalList], $item, $Time[0] & '/' & $Time[1] & '/' & $Time[2] & ' ' & $Time[3] & ':' & $Time[4] & ':' & $Time[5], $iIndex)
                $iIndex += 1
            EndIf
            If $Columns[5][1] Then;Accessed
                $Time = FileGetTime($sFile, 2)
                _GUICtrlListView_AddSubItem($aGUI[$g_LocalList], $item, $Time[0] & '/' & $Time[1] & '/' & $Time[2] & ' ' & $Time[3] & ':' & $Time[4] & ':' & $Time[5], $iIndex)
                $iIndex += 1
            EndIf
            $iIndex = 1
        Next
    EndIf
    _GUICtrlListView_EndUpdate($aHandles[$g_hLocalList])
    If $iFiles = 0 Then
        GUICtrlSetData($aGUI[$g_lbLocalCount], $iDirs & ' Directorys, ' & $iFiles & ' Files ')
    Else
        GUICtrlSetData($aGUI[$g_lbLocalCount], $iDirs & ' Directorys, ' & $iFiles & ' Files ' & '[' & _bytes($iSize) & ']')
    EndIf
    _ComboHistoryAdd($aGUI[$g_cbLocal], $sComboLocal, $sDirectory)
    $gsLocalCurrent = $sDirectory
EndFunc   ;==>_LocalGo
Func _LocalBack()
    If $gaLocalHistory[0] = '' Then Return
    _LocalGo(_Pop_History($gaLocalHistory))
    _LocalSetBackTip($gaLocalHistory[0])
EndFunc   ;==>_LocalBack
Func _Localcreatefolder()
    Local $bMouseHover = _MouseHover_Disable()
    Local $sName = InputBox('Create New Directory', 'Enter Directory Name', '', " M", Default, 130, Default, Default, 0, $aGUI[$g_hGUI])
    DirCreate(StringReplace($gsLocalCurrent & '\' & $sName, '\\', '\'))
    _LocalGo($gsLocalCurrent);refresh
    If $bMouseHover Then _MouseHover_Enable()
EndFunc   ;==>_Localcreatefolder
Func _LocalDelete()
    Local $aLocalSelected = _GUICtrlListView_GetSelectedIndices($aHandles[$g_hLocalList], True)
    If $aLocalSelected[0] = 0 Then Return
    Local $bMouseHover = _MouseHover_Disable()
    If MsgBox(36, 'Confirm File Delete', 'Are you sure you want to delete selected files?', 0, $aGUI[$g_hGUI]) = 7 Then
        If $bMouseHover Then _MouseHover_Enable()
        Return
    EndIf
    Local $i, $sFileName
    For $i = 1 To $aLocalSelected[0]
        $sFileName = StringReplace($gsLocalCurrent & '\' & _GUICtrlListView_GetItemText($aGUI[$g_LocalList], $aLocalSelected[$i], 0), '\\', '\')
        If StringInStr(FileGetAttrib($sFileName), 'D') = 0 Then
            FileDelete($sFileName)
        Else
            DirRemove($sFileName, 1)
        EndIf
    Next
    _GUICtrlListView_DeleteItemsSelected($aHandles[$g_hLocalList])
    _LocalGo($gsLocalCurrent);refresh
    If $bMouseHover Then _MouseHover_Enable()
EndFunc   ;==>_LocalDelete
Func _LocalSetBackTip($sDir)
    If $sDir = 'My Computer' Or StringLen($sDir) = 3 Then Return GUICtrlSetTip($aGUI[$g_bLocalBack], 'Back to ' & $sDir)
    $sDir = StringTrimLeft($sDir, StringInStr($sDir, '\', 0, -1))
    If $sDir = '' Then Return GUICtrlSetTip($aGUI[$g_bLocalBack], 'Navigate Back')
    GUICtrlSetTip($aGUI[$g_bLocalBack], 'Back to ' & $sDir)
EndFunc   ;==>_LocalSetBackTip
#endregion Local Navigation Functions....................................
;
#region Ftp Navigation Functions......................................
Func _FTPDirSwitch($index)
    Local $sCurrentFTPDir, $sChangeDir, $aItem
    $sCurrentFTPDir = _FTP_DirGetCurrent($ghFTPConnect)
    If _GUICtrlListView_GetItemText($aGUI[$g_FTPList], $index, 0) = '[..]' Then
        $sChangeDir = _FTPParent($sCurrentFTPDir)
    Else
        $aItem = _GUICtrlListView_GetItem($aGUI[$g_FTPList], $index)
        If $aItem[4] = $FOLDER_ICON_INDEX Then
            If $sCurrentFTPDir = '/' Then
                $sChangeDir = '/' & _GUICtrlListView_GetItemText($aGUI[$g_FTPList], $index)
            Else
                $sChangeDir = $sCurrentFTPDir & '/' & _GUICtrlListView_GetItemText($aGUI[$g_FTPList], $index)
            EndIf
        Else
            Return
        EndIf
    EndIf
    _FTPGo($sChangeDir)
EndFunc   ;==>_FTPDirSwitch
Func _FTPGo($sChangeDir, $iInternet_Flag = $INTERNET_FLAG_HYPERLINK)
    Local $sFTPCurrent = _FTP_DirGetCurrent($ghFTPConnect)
    If $sChangeDir = $sFTPCurrent Then Return
    _RichEdit_AppendColor('Changing Directories...', $cPurp, True)
    _Push_History($sFTPCurrent, $gaFTPHistory)
    _FTPSetBackTip($sFTPCurrent)
    _FTP_DirSetCurrent($ghFTPConnect, $sChangeDir)
    If @error Then
        _RichEdit_AppendColor('ERROR: FTP Directory Change to ', $cRed)
        _RichEdit_AppendColor('"' & $sChangeDir & '"')
        _RichEdit_AppendColor(' Failed...', $cRed, True)
        _Pop_History($gaFTPHistory)
        GUICtrlSetState($aGUI[$g_FTPList], $GUI_FOCUS);RichEdit keeps stealing Focus
        Return
    EndIf
    _ComboHistoryAdd($aGUI[$g_cbFTP], $sComboFTP, $sChangeDir)
    Local $Start = TimerInit()
    _FtpRefresh($iInternet_Flag)
    ConsoleWrite('Time = ' & TimerDiff($Start) & @CRLF)
    _RichEdit_AppendColor('Change Successful. ', $cPurp)
    _RichEdit_AppendColor('"' & $sChangeDir & '"')
    _RichEdit_AppendColor(' is the Current Directory', $cPurp, True)
    GUICtrlSetState($aGUI[$g_FTPList], $GUI_FOCUS);RichEdit keeps stealing Focus
EndFunc   ;==>_FTPGo
Func _FTPSetBackTip($sDir)
    If $sDir = '/' Then Return GUICtrlSetTip($aGUI[$g_bFTPBack], 'Back to /')
    $sDir = StringTrimLeft($sDir, StringInStr($sDir, '/', 0, -1))
    If $sDir = '' Then Return GUICtrlSetTip($aGUI[$g_bFTPBack], 'Navigate Back')
    GUICtrlSetTip($aGUI[$g_bFTPBack], 'Back to ' & $sDir)
EndFunc   ;==>_FTPSetBackTip
Func _FTPParent($sCurrentDir)
    Local $pos = StringInStr($sCurrentDir, '/', 0, -1)
    If $pos = 1 Then Return '/'
    Return StringLeft($sCurrentDir, $pos - 1)
EndFunc   ;==>_FTPParent
Func _FTPBack()
    If $gaFTPHistory[0] = '' Then Return GUICtrlSetTip($aGUI[$g_bFTPBack], 'Navigate Back')
    Local $Back = _Pop_History($gaFTPHistory)
    _FTPSetBackTip($gaFTPHistory[0])
    _FTP_DirSetCurrent($ghFTPConnect, $Back)
    If @error Then
        _RichEdit_AppendColor('ERROR: FTP Directory Change to ', $cRed)
        _RichEdit_AppendColor($Back)
        _RichEdit_AppendColor(' Failed...', $cRed, True)
        Return
    EndIf
    _RichEdit_AppendColor('Changing Directories...', $cPurp, True)
    _ComboHistoryAdd($aGUI[$g_cbFTP], $sComboFTP, $Back)
    _FtpRefresh($INTERNET_FLAG_FROM_CACHE)
    _RichEdit_AppendColor('Change Successful. ', $cPurp)
    _RichEdit_AppendColor('"' & $Back & '"')
    _RichEdit_AppendColor(' is the Current Directory', $cPurp, True)
    GUICtrlSetState($aGUI[$g_FTPList], $GUI_FOCUS)
EndFunc   ;==>_FTPBack
Func _FtpRefresh($iFlag = Default)

    If $iFlag = Default Then $iFlag = BitAND($INTERNET_FLAG_RELOAD, $INTERNET_FLAG_NEED_FILE)

    Local $i, $item, $iIcon, $iDirs = 0, $iFiles = 0, $iSize = 0, $iIndex = 1
    Local $FileAttributes, $sFileName, $iFileSize, $sFilesize, $Filetime, $callFindNext, $iDirIndex = -1

    GUICtrlSetData($aGUI[$g_lbFTPCount], $iDirs & ' Directorys, ' & $iFiles & ' Files ' & '[' & _bytes($iSize) & ']')
    _GUICtrlListView_DeleteAllItems($aHandles[$g_hFTPList])
    If _FTP_DirGetCurrent($ghFTPConnect) <> '/' Then
        _GUICtrlListView_AddItem($aGUI[$g_FTPList], "[..]", $FOLDER_ICON_INDEX)
        $iDirIndex += 1
    EndIf

    Static $tWIN32_FIND_DATA = DllStructCreate($tagWIN32_FIND_DATA)
    Static $pWIN32_FIND_DATA = DllStructGetPtr($tWIN32_FIND_DATA)
    Local $callFindFirst = DllCall($__ghWinInet_FTP, 'handle', 'FtpFindFirstFileW', 'handle', $ghFTPConnect, 'wstr', "", 'ptr', $pWIN32_FIND_DATA, 'dword', $iFlag, 'dword_ptr', $ghFTPCallBack)
    If @error Then Return SetError(1, _WinAPI_GetLastError(), 0)
    If Not @error And $callFindFirst[0] Then
        _GUICtrlListView_BeginUpdate($aHandles[$g_hFTPList])
        Local $Columns = IniReadSection($aConnectGUI[$g_sINIHistory], 'FTPColumns')
        For $i = 1 To 5
            $Columns[$i][1] = Int($Columns[$i][1])
        Next
        Local $UpdateTimer = TimerInit()
        Do
            If TimerDiff($UpdateTimer) > 200 Then
                GUICtrlSetData($aGUI[$g_lbFTPCount], $iDirs & ' Directorys, ' & $iFiles & ' Files ' & '[' & _bytes($iSize) & ']')
                $UpdateTimer = TimerInit()
            EndIf

            $sFileName = DllStructGetData($tWIN32_FIND_DATA, "cFileName")
            $FileAttributes = DllStructGetData($tWIN32_FIND_DATA, "dwFileAttributes")

            If BitAND($FileAttributes, $FILE_ATTRIBUTE_DIRECTORY) Then
                $iDirs += 1
                $iDirIndex += 1
                $sFilesize = 'DIR'
                $item = _GUICtrlListView_InsertItem($aHandles[$g_hFTPList], $sFileName, $iDirIndex, $FOLDER_ICON_INDEX)
            Else
                $iFiles += 1
                $iFileSize = _WinAPI_MakeQWord(DllStructGetData($tWIN32_FIND_DATA, "nFileSizeLow"), DllStructGetData($tWIN32_FIND_DATA, "nFileSizeHigh"))
                $iSize += $iFileSize
                $sFilesize = _bytes($iFileSize)
                $iIcon = _GUIImageList_GetFileIconIndex('c:\blank.' & StringRight($sFileName, 3))
                $item = _GUICtrlListView_AddItem($aHandles[$g_hFTPList], $sFileName, $iIcon)
            EndIf

            If $Columns[1][1] Then ;size
                _GUICtrlListView_AddSubItem($aGUI[$g_FTPList], $item, $sFilesize, $iIndex)
                $iIndex += 1
            EndIf
            If $Columns[2][1] Then;Modified
                $Filetime = DllStructCreate($tagFileTime, DllStructGetPtr($tWIN32_FIND_DATA, "ftLastWriteTime"))
                _GUICtrlListView_AddSubItem($aGUI[$g_FTPList], $item, _Date_Time_FileTimeToStr($Filetime, 1), $iIndex)
                $iIndex += 1
            EndIf
            If $Columns[3][1] Then;Attributes
                _GUICtrlListView_AddSubItem($aGUI[$g_FTPList], $item, $FileAttributes, $iIndex)
                $iIndex += 1
            EndIf
            If $Columns[4][1] Then;Creation
                $Filetime = DllStructCreate($tagFileTime, DllStructGetPtr($tWIN32_FIND_DATA, "ftCreationTime"))
                _GUICtrlListView_AddSubItem($aGUI[$g_FTPList], $item, _Date_Time_FileTimeToStr($Filetime, 1), $iIndex)
                $iIndex += 1
            EndIf
            If $Columns[5][1] Then;Accessed
                $Filetime = DllStructCreate($tagFileTime, DllStructGetPtr($tWIN32_FIND_DATA, "ftLastAccessTime"))
                _GUICtrlListView_AddSubItem($aGUI[$g_FTPList], $item, _Date_Time_FileTimeToStr($Filetime, 1), $iIndex)
                $iIndex += 1
            EndIf
            $iIndex = 1

            $callFindNext = DllCall($__ghWinInet_FTP, 'bool', 'InternetFindNextFileW', 'handle', $callFindFirst[0], 'ptr', $pWIN32_FIND_DATA)
            If @error Then Return SetError(2, _WinAPI_GetLastError(), 0)
        Until Not $callFindNext[0]

        DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $callFindFirst[0])
        _GUICtrlListView_EndUpdate($aHandles[$g_hFTPList])
    EndIf

    GUICtrlSetData($aGUI[$g_lbFTPCount], $iDirs & ' Directorys, ' & $iFiles & ' Files ' & '[' & _bytes($iSize) & ']')

EndFunc   ;==>_FtpRefresh
#endregion Ftp Navigation Functions......................................
#region FTP Functions.................................................
Func _FTP_Connect_GUI()
    Local $GUI_Connect, $butConnect, $taddress, $server_History
    Local $bMouseHover = _MouseHover_Disable()
    Local $sLastIP = IniRead($aConnectGUI[$g_sINIHistory], 'Last', 'IP', '')
    Local $aINIServers = IniReadSectionNames($aConnectGUI[$g_sINIHistory])
    For $i = 1 To $aINIServers[0]
        Switch $aINIServers[$i]
            Case 'Abort', 'Last', $sLastIP, 'FTPColumns', 'LocalColumns', 'Queue'
            Case Else
                $server_History &= $aINIServers[$i] & '|'
        EndSwitch
    Next
    $server_History = StringTrimRight($server_History, 1)
    $GUI_Connect = GUICreate("FTP Connect", 323, 140, Default, Default, Default, Default, $aGUI[$g_hGUI])
    GUISwitch($GUI_Connect)
    $aGUI[$g_bActive] = False
    $aConnectGUI[$g_sIP] = GUICtrlCreateCombo(IniRead($aConnectGUI[$g_sINIHistory], 'Last', 'IP', ''), 80, 15, 166, 21)
    $aConnectGUI[$g_hIP] = GUICtrlGetHandle($aConnectGUI[$g_sIP])
    GUICtrlCreateLabel("Server or Url:", 10, 20, 66, 17)
    $aConnectGUI[$g_iPort] = GUICtrlCreateInput(IniRead($aConnectGUI[$g_sINIHistory], 'Last', 'Port', ''), 285, 15, 26, 21)
    GUICtrlCreateLabel("Port:", 255, 20, 26, 17)
    $aConnectGUI[$g_sUser] = GUICtrlCreateInput(IniRead($aConnectGUI[$g_sINIHistory], 'Last', 'User', ''), 80, 45, 231, 21)
    GUICtrlCreateLabel("User Name:", 10, 50, 60, 17)
    Local $Decrypt_Pass = IniRead($aConnectGUI[$g_sINIHistory], 'Last', 'Pass', '')
    If $Decrypt_Pass <> '' Then $Decrypt_Pass = _StringEncrypt(0, $Decrypt_Pass, 'autoitrocks')
    $aConnectGUI[$g_sPass] = GUICtrlCreateInput($Decrypt_Pass, 80, 75, 231, 21, $ES_PASSWORD)
    GUICtrlCreateLabel("Password:", 10, 80, 53, 17)
    $butConnect = GUICtrlCreateButton("Connect", 100, 105, 106, 26, 0)
    If $server_History <> '' Then GUICtrlSetData($aConnectGUI[$g_sIP], $server_History)
    GUISetState(@SW_SHOW, $GUI_Connect)
    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($GUI_Connect)
                Return ''
            Case $butConnect
                Local $tIP = GUICtrlRead($aConnectGUI[$g_sIP])
                If $tIP = '' Then
                    MsgBox(0, 'ERROR', 'Must Enter Server or Url.', 5)
                    ContinueLoop
                EndIf
                $taddress = _CheckIP($tIP)
                Local $tPass = GUICtrlRead($aConnectGUI[$g_sPass]), $tUser = GUICtrlRead($aConnectGUI[$g_sUser]), $tPort = GUICtrlRead($aConnectGUI[$g_iPort])
                Local $aSearch = _ArraySearch($aINIServers, $tIP)
                If @error Then;if not found then save address. If its not an array than history file is empty
                    If $tPass <> '' Then $tPass = _StringEncrypt(1, $tPass, 'autoitrocks')
                    Local $aData[5][2] = [["User", $tUser],["Pass", $tPass],["Port", $tPort],["DIR_History", ''],['Queue', '']]
                    IniWriteSection($aConnectGUI[$g_sINIHistory], $tIP, $aData, 0)
                Else;verify that data is still the same.
                    If $tPass <> '' Then $tPass = _StringEncrypt(1, $tPass, 'autoitrocks')
                    If $tUser <> IniRead($aConnectGUI[$g_sINIHistory], $tIP, 'User', '') Then IniWrite($aConnectGUI[$g_sINIHistory], $tIP, 'User', $tUser)
                    If $tPass <> IniRead($aConnectGUI[$g_sINIHistory], $tIP, 'Pass', '') Then IniWrite($aConnectGUI[$g_sINIHistory], $tIP, 'Pass', $tPass)
                    If $tPort <> IniRead($aConnectGUI[$g_sINIHistory], $tIP, 'Port', '') Then IniWrite($aConnectGUI[$g_sINIHistory], $tIP, 'Port', $tPort)
                    Local $DirHistory = IniRead($aConnectGUI[$g_sINIHistory], $tIP, 'DIR_History', '')
                    GUICtrlSetData($aGUI[$g_cbFTP], $DirHistory)
                    Local $sQueueHistory = IniRead($aConnectGUI[$g_sINIHistory], $tIP, 'Queue', '')
                    If $sQueueHistory <> '' Then
                        _LoadQueue($sQueueHistory)
                        IniWrite($aConnectGUI[$g_sINIHistory], $tIP, 'Queue', '')
                    EndIf
                    $sComboFTP = $DirHistory
                EndIf
                Local $aLast[4][2] = [["User", $tUser],["Pass", $tPass],["Port", $tPort],["IP", $tIP]]
                IniWriteSection($aConnectGUI[$g_sINIHistory], 'Last', $aLast, 0)
                GUISetState(@SW_HIDE, $GUI_Connect)
                _connect($taddress, $tUser, GUICtrlRead($aConnectGUI[$g_sPass]), $tPass)
                If @error = -3 Then
                    _RichEdit_AppendColor('Failed to Connect to Server..', $cRed, True)
                    GUISetState(@SW_SHOW, $GUI_Connect)
                    ContinueLoop
                EndIf
                GUIDelete($GUI_Connect)
                $aGUI[$g_bActive] = True
                GUISwitch($aGUI[$g_hGUI])
                If $bMouseHover Then _MouseHover_Enable()
                Return
        EndSwitch
    WEnd
EndFunc   ;==>_FTP_Connect_GUI
Func _LoadQueue($sQueue)
    Local $aQueueSplit, $aItemsplit, $i, $iIcon, $iUpDownIcon, $sSource, $sDest, $sItem
    $aQueueSplit = StringSplit($sQueue, '|')
    For $i = 1 To $aQueueSplit[0]
        $aItemsplit = StringSplit($aQueueSplit[$i], ';')
        If $aItemsplit[2] = 'DIR' Then
            $iIcon = $FOLDER_ICON_INDEX
        Else
            $iIcon = _GUIImageList_GetFileIconIndex($aItemsplit[4])
        EndIf

        If $aItemsplit[1] = 'download' Then
            $sSource = $aItemsplit[5] & $aItemsplit[4]
            $sDest = $aItemsplit[3]
            $iUpDownIcon = $aGUI[$g_iDownICO]
        Else
            $sSource = $aItemsplit[3] & $aItemsplit[4]
            $sDest = $aItemsplit[5]
            $iUpDownIcon = $aGUI[$g_iUpICO]
        EndIf

        $sItem = _GUICtrlListView_AddItem($aGUI[$g_QueueList], $sSource, $iIcon)
        _GUICtrlListView_AddSubItem($aGUI[$g_QueueList], $sItem, $sDest, 1)
        _GUICtrlListView_SetItemStateImage($aGUI[$g_QueueList], $sItem, $iUpDownIcon)
        _ArrayAdd($gaQueue, $aQueueSplit[$i])
    Next
EndFunc   ;==>_LoadQueue
Func _CheckIP($ip) ; Verifys corrent IP format or converts URL to IP. Needs to be rewrote.
    Local $ipcheck, $newip
    $ipcheck = StringReplace($ip, '.', '')
    If StringIsDigit($ipcheck) Then
        $gsServer_IP = $ip
        $gsServer_Name = ''
        Return $ip
    EndIf
    $gsServer_Name = $ip;
    $ip = StringReplace($ip, 'ftp://', '')
    $ip = StringReplace($ip, 'ftp:/', '')
    If StringRight($ip, 1) = '/' Then $ip = StringTrimRight($ip, 1)
    TCPStartup()
    $newip = TCPNameToIP($ip)
    TCPShutdown()
    If $newip = '' Then
        MsgBox(0, 'ERROR', 'Problem with Server address.', 5)
        Return 0
    EndIf
    $gsServer_IP = $newip
    Return $newip
EndFunc   ;==>_CheckIP
Func _connect($sFTP_IPAddress, $sUser, $sPass, $iPort, $sSession = 'session');;;;
    $ghFTPOpen = _FTP_Open($sSession)
    _InternetSetOption($ghFTPOpen, $INTERNET_OPTION_RECEIVE_TIMEOUT, 5000)
    $ghFTPCallBack = _FTP_SetStatusCallback($ghFTPOpen, '_FTP_StatusHandler')
    $ghFTPConnect = _FTP_Connect($ghFTPOpen, $sFTP_IPAddress, $sUser, $sPass, 1, $iPort, 1, 0, $ghFTPCallBack)
    If @error = -1 Then
        $gsServer_IP = ''
        $gsServer_Name = ''
        Return SetError(-3)
    EndIf
    $gbFTP_NOReconnet = False
    $gsServer_IP = $sFTP_IPAddress
    $gaConnectionInfo[0] = $sFTP_IPAddress
    $gaConnectionInfo[1] = $sUser
    $gaConnectionInfo[2] = $sPass
    $gaConnectionInfo[3] = $iPort
    _MsgSend('Worker', 1 & ';' & $gaConnectionInfo[0] & ';' & $gaConnectionInfo[1] & ';' & $gaConnectionInfo[2] & ';' & $gaConnectionInfo[3])
    GUICtrlSetState($aGUI[$g_FileItem1], $GUI_DISABLE)
    _Statusbar(2)
    _FtpRefresh()
    _ComboHistoryAdd($aGUI[$g_cbFTP], $sComboFTP, '/')
EndFunc   ;==>_connect
Func _FTP_Disconnect()
    If $gbFTP_Connected Then
        If $gsServer_Name <> '' Then
            IniWrite($aConnectGUI[$g_sINIHistory], $gsServer_Name, 'DIR_History', $sComboFTP)
        Else
            IniWrite($aConnectGUI[$g_sINIHistory], $gsServer_IP, 'DIR_History', $sComboFTP)
        EndIf
        If (UBound($gaQueue) - 1) > 0 Then
            Local $sQueue = StringTrimLeft(_ArrayToString($gaQueue, '|'), 1)
            If $gsServer_Name <> '' Then
                IniWrite($aConnectGUI[$g_sINIHistory], $gsServer_Name, 'Queue', $sQueue)
            Else
                IniWrite($aConnectGUI[$g_sINIHistory], $gsServer_IP, 'Queue', $sQueue)
            EndIf
        EndIf
        Global $gaQueue[1]
        _GUICtrlListView_DeleteAllItems($aHandles[$g_hQueuelist])
        _GUICtrlListView_DeleteAllItems($aHandles[$g_hFTPList])
        $gsServer_IP = ''
        $gsServer_Name = ''
        $sComboFTP = ''
        GUICtrlSetData($aGUI[$g_cbFTP], '', '')
        $FTP_State = $giIdle
        $aTimers[$g_bIdleClock] = False
        _GUICtrlStatusBar_Destroy($aGUI[$g_hStatusBar])
        Local $StatusBar_PartsWidth[4] = [200, ($aGUI[$g_iWidth] / 2), ($aGUI[$g_iWidth] - 80), -1]
        Local $StatusBar_PartsText[4] = ["Not Connected", "", "", $CPU]
        $aGUI[$g_hStatusBar] = _GUICtrlStatusBar_Create($aGUI[$g_hGUI], $StatusBar_PartsWidth, $StatusBar_PartsText)
        _GUICtrlStatusBar_SetMinHeight($aGUI[$g_hStatusBar], 21)
        _FTP_Close($ghFTPOpen)
    EndIf
EndFunc   ;==>_FTP_Disconnect
Func _FTPRemovedir($sFTPDirectory)
    Local $aFile, $hSearch, $sWorkingdir, $sFolderList, $i, $bFirst, $aFolderStack[2] = [1, $sFTPDirectory]
    While $aFolderStack[0] > 0
        $sWorkingdir = $aFolderStack[$aFolderStack[0]]
        $aFolderStack[0] -= 1
        $aFile = _FTP_FindFileFirst($ghFTPConnect, $sWorkingdir & '/*', $hSearch, $INTERNET_FLAG_RESYNCHRONIZE)
        If Not @error Then
            $bFirst = True
            While 1
                If Not $bFirst Then
                    $aFile = _FTP_FindFileNext($hSearch)
                    If @error Then ExitLoop
                EndIf
                If $aFile[1] = 16 Then
                    $aFolderStack[0] += 1
                    If UBound($aFolderStack) <= $aFolderStack[0] Then ReDim $aFolderStack[UBound($aFolderStack) * 2]
                    $aFolderStack[$aFolderStack[0]] = $sWorkingdir & "/" & $aFile[10]
                    $sFolderList &= $sWorkingdir & "/" & $aFile[10] & ';'
                Else
                    _FTP_FileDelete($ghFTPConnect, $sWorkingdir & "/" & $aFile[10])
                    _RichEdit_AppendColor('File ', $cRed)
                    _RichEdit_AppendColor('"' & $sWorkingdir & '/' & $aFile[10] & '"')
                    _RichEdit_AppendColor(' was Deleted', $cRed, True)
                EndIf
                $bFirst = False
            WEnd
        EndIf
        _FTP_FindFileClose($hSearch)
    WEnd
    $aFolderStack = StringSplit(StringTrimRight($sFolderList, 1), ';')
    For $i = $aFolderStack[0] To 1 Step -1
        _FTP_DirDelete($ghFTPConnect, $aFolderStack[$i])
        _RichEdit_AppendColor('Directory ', $cRed)
        _RichEdit_AppendColor('"' & $aFolderStack[$i] & '"')
        _RichEdit_AppendColor(' was Deleted', $cRed, True)
    Next
EndFunc   ;==>_FTPRemovedir
Func _FTP_Delete()
    Local $aFTPSelected = _GUICtrlListView_GetSelectedIndices($aHandles[$g_hFTPList], True)
    If $aFTPSelected[0] = 0 Then Return
    Local $bMouseHover = _MouseHover_Disable()
    If MsgBox(36 + 262144, 'Confirm File Delete', 'Are you sure you want to delete selected files?', 0, $aGUI[$g_hGUI]) = 7 Then; 7 = cancel
        If $bMouseHover Then _MouseHover_Enable()
        Return
    EndIf
    Local $sCurrentFTP = _FTP_DirGetCurrent($ghFTPConnect)
    Local $sFileName, $sFileType, $i
    For $i = 1 To $aFTPSelected[0]
        $sFileName = _GUICtrlListView_GetItemText($aGUI[$g_FTPList], $aFTPSelected[$i], 0)
        $sFileType = _GUICtrlListView_GetItemText($aGUI[$g_FTPList], $aFTPSelected[$i], 1)
        If $sFileType = 'DIR' Then
            _FTPRemovedir($sCurrentFTP & '/' & $sFileName)
            _FTP_DirSetCurrent($ghFTPConnect, $sCurrentFTP)
            If _FTP_DirDelete($ghFTPConnect, $sFileName) Then
                _RichEdit_AppendColor('Directory ', $cRed)
                _RichEdit_AppendColor('"' & $sCurrentFTP & '/' & $sFileName & '"')
                _RichEdit_AppendColor(' was Deleted', $cRed, True)
            EndIf
        Else
            If _FTP_FileDelete($ghFTPConnect, $sFileName) Then
                _RichEdit_AppendColor('File ', $cRed)
                _RichEdit_AppendColor('"' & $sCurrentFTP & '/' & $sFileName & '"')
                _RichEdit_AppendColor(' was Deleted', $cRed, True)
            EndIf
        EndIf
    Next
    _GUICtrlListView_DeleteItemsSelected($aHandles[$g_hFTPList])
    _FtpRefresh($INTERNET_FLAG_RESYNCHRONIZE)
    If $bMouseHover Then _MouseHover_Enable()
EndFunc   ;==>_FTP_Delete
Func _FTP_StatusHandler($hInternet, $dwContent, $dwInternetStatus, $lpvStatusInformation, $dwStatusInformationLength)

    Switch $dwInternetStatus
        Case $INTERNET_STATUS_RESOLVING_NAME
            _RichEdit_AppendColor('Resolving Name...', $cBlue, True)
        Case $INTERNET_STATUS_NAME_RESOLVED
            _RichEdit_AppendColor('Name Resolved', $cBlue, True)
        Case $INTERNET_STATUS_CONNECTING_TO_SERVER
            _RichEdit_AppendColor('Connecting to Server: ', $cBlue)
            _RichEdit_AppendColor($gsServer_Name, $cPink)
            _RichEdit_AppendColor(' (' & $gsServer_IP & ')', $cGreen, True)
        Case $INTERNET_STATUS_CONNECTED_TO_SERVER
            _RichEdit_AppendColor('Connected!', $cBlue, True)
            $gbFTP_Connected = True
        Case $INTERNET_STATUS_CONNECTION_CLOSED
            _RichEdit_AppendColor('Connection Closed.', $cBlue, True)
            $gbFTP_Connected = False
        Case $INTERNET_STATUS_CLOSING_CONNECTION
            _RichEdit_AppendColor('Closing Connection...', $cBlue, True)
        Case $INTERNET_STATUS_STATE_CHANGE
            _RichEdit_AppendColor('State Change Value = ', $cGreen)
            _RichEdit_AppendColor($lpvStatusInformation, $cGreen, True)
        Case Else
            $aTimers[$g_tIdleClock] = TimerInit()
    EndSwitch

EndFunc   ;==>_FTP_StatusHandler
#endregion FTP Functions.................................................
#region Column Functions..............................................
Func _Columns($hList, $sSection, $bStartup = False)

    Local $iColumnCount = _GUICtrlListView_GetColumnCount($hList)
    Local $Columns = IniReadSection($aConnectGUI[$g_sINIHistory], $sSection)

    If Not $bStartup Then
        For $i = 1 To $iColumnCount
            _GUICtrlListView_DeleteColumn($hList, 1)
        Next
    Else
        _GUICtrlListView_SetColumnWidth($hList, 0, Int(IniRead($aConnectGUI[$g_sINIHistory], $sSection, 'File', 350)))
    EndIf

    For $i = 1 To 5
        If Int($Columns[$i][1]) > 0 Then _GUICtrlListView_AddColumn($hList, $Columns[$i][0], $Columns[$i][1])
    Next

    If $hList = $aHandles[$g_hFTPList] Then Return _FtpRefresh()
    _LocalGo($gsLocalCurrent);refresh

EndFunc   ;==>_Columns
Func _SaveColumns($hList, $sSection)
    Local $i, $iCount, $aColunm

    $iCount = _GUICtrlListView_GetColumnCount($hList)

    For $i = 0 To $iCount - 1
        $aColunm = _GUICtrlListView_GetColumn($hList, $i)
        IniWrite($aConnectGUI[$g_sINIHistory], $sSection, $aColunm[5], $aColunm[4])
    Next
EndFunc   ;==>_SaveColumns
#endregion Column Functions..............................................
#region GUI Notification Functions....................................
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iCode
        Case $LVN_KEYDOWN ; A key has been pressed
            Local $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
            Switch DllStructGetData($tInfo, "VKey")
                Case 46;22216750 ;Delete Key
                    Switch $hWndFrom
                        Case $aHandles[$g_hLocalList]
                            _LocalDelete()
                        Case $aHandles[$g_hFTPList]
                            If $gbFTP_Connected Then _FTP_Delete()
                        Case $aHandles[$g_hQueuelist]
                            _Queue_Delete_items()
                    EndSwitch
                Case 8;917512;Backspace key
                    Switch $hWndFrom
                        Case $aHandles[$g_hLocalList]
                            _LocalBack()
                        Case $aHandles[$g_hFTPList]
                            If $gbFTP_Connected Then _FTPBack()
                    EndSwitch
                Case 113; F2 Key
                    Local $iTotalSelected = _GUICtrlListView_GetSelectedCount($hWndFrom)
                    If $iTotalSelected <> 1 Then Return $GUI_RUNDEFMSG
                    Switch $hWndFrom
                        Case $aHandles[$g_hLocalList]
                            If $gsLocalCurrent = 'My Computer' Then Return $GUI_RUNDEFMSG
                            _Rename($aHandles[$g_hLocalList])
                        Case $aHandles[$g_hFTPList]
                            If Not $gbFTP_Connected Or _FTP_DirGetCurrent($ghFTPConnect) = '/' Then Return $GUI_RUNDEFMSG
                            _Rename($aHandles[$g_hFTPList])
                    EndSwitch
;~                  ConsoleWrite(DllStructGetData($tInfo, "VKey") & @CRLF)
            EndSwitch
        Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
            Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
            Switch $hWndFrom
                Case $aHandles[$g_hLocalList]
                    _LocalDirSwitch(DllStructGetData($tInfo, "Index"))
                Case $aHandles[$g_hFTPList]
                    _FTPDirSwitch(DllStructGetData($tInfo, "Index"))
            EndSwitch
        Case $NM_RCLICK
            Switch $hWndFrom
                Case $aHandles[$g_hQueuelist]
                    _QueueListView_RClick()
                Case $aHandles[$g_hLocalList]
                    _LocalListView_RClick()
                Case $aHandles[$g_hFTPList]
                    _FTPListView_RClick()
                Case $aHandles[$g_hFTPListHeader]
                    _RClick_Attributes($aHandles[$g_hFTPList], 'FTPColumns')
                Case $aHandles[$g_hLocalListHeader]
                    _RClick_Attributes($aHandles[$g_hLocalList], 'LocalColumns')
            EndSwitch
;~      Case $NM_KILLFOCUS
;~      Case $NM_SETFOCUS
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $hWndFrom)
    #forceref $hWnd, $iMsg
    Local $iIDFrom, $iCode;, $hWndEdit
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $hWndFrom
        Case $aHandles[$g_hFTPCombo]
            Switch $iCode
                Case $CBN_KILLFOCUS ; Sent when a combo box loses the keyboard focus
                    AdlibUnRegister('_ComboFTP_Monitor_EnterKey')
                Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
                    _FTPGo(GUICtrlRead($aGUI[$g_cbFTP]))
                Case $CBN_SETFOCUS ; Sent when a combo box receives the keyboard focus
                    AdlibRegister('_ComboFTP_Monitor_EnterKey', 75)
            EndSwitch
        Case $aHandles[$g_hLocalCombo]
            Switch $iCode
                Case $CBN_KILLFOCUS ; Sent when a combo box loses the keyboard focus
                    AdlibUnRegister('_ComboLocal_Monitor_EnterKey')
                Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
                    _Push_History($gsLocalCurrent, $gaLocalHistory)
                    _LocalGo(GUICtrlRead($aGUI[$g_cbLocal]))
                Case $CBN_SETFOCUS ; Sent when a combo box receives the keyboard focus
                    AdlibRegister('_ComboLocal_Monitor_EnterKey', 75)
            EndSwitch
        Case $aConnectGUI[$g_hIP]
            If $iCode = $CBN_SELCHANGE Then; Sent when the user changes the current selection in the list box of a combo box
                Local $sIPRead = GUICtrlRead($aConnectGUI[$g_sIP])
                Local $Decrypt_Pass = IniRead($aConnectGUI[$g_sINIHistory], $sIPRead, 'Pass', '')
                If $Decrypt_Pass <> '' Then $Decrypt_Pass = _StringEncrypt(0, $Decrypt_Pass, 'autoitrocks')
                GUICtrlSetData($aConnectGUI[$g_sPass], $Decrypt_Pass)
                GUICtrlSetData($aConnectGUI[$g_sUser], IniRead($aConnectGUI[$g_sINIHistory], $sIPRead, 'User', ''))
                GUICtrlSetData($aConnectGUI[$g_iPort], IniRead($aConnectGUI[$g_sINIHistory], $sIPRead, 'Port', ''))
;~              ConsoleWrite($hWndFrom & @CRLF & $iCode & @CRLF)
            EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    $aGUI[$g_iWidth] = _WinAPI_LoWord($ilParam)
    ;$iHeight = _WinAPI_HiWord($ilParam)
    _GUICtrlStatusBar_Resize($aGUI[$g_hStatusBar])
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE
#endregion GUI Notification Functions....................................
#region Right Click Menues............................................
Func _FTPListView_RClick()
    Local Enum $idQueue = 1000, $idTransfer, $idDelete, $idRename, $idRefresh, $idFolder, $idAbort, $idConnect
    Local $hMenu = _GUICtrlMenu_CreatePopup()
    Local $iTotalSelected = _GUICtrlListView_GetSelectedCount($aHandles[$g_hFTPList])

    If $gbFTP_Connected Then
        If $FTP_State <> $giIdle Then _GUICtrlMenu_AddMenuItem($hMenu, "ABORT Transfer", $idAbort)
        If $iTotalSelected Then
            If $gsLocalCurrent <> 'My Computer' Then _GUICtrlMenu_AddMenuItem($hMenu, "Queue", $idQueue)
            If $FTP_State = $giIdle And $gsLocalCurrent <> 'My Computer' Then _GUICtrlMenu_AddMenuItem($hMenu, "Transfer", $idTransfer)
            _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idDelete)
        EndIf
        If $iTotalSelected = 1 Then _GUICtrlMenu_AddMenuItem($hMenu, "Rename", $idRename)
        _GUICtrlMenu_AddMenuItem($hMenu, "Refresh", $idRefresh)
        _GUICtrlMenu_AddMenuItem($hMenu, "Create Folder", $idFolder)
    Else
        _GUICtrlMenu_AddMenuItem($hMenu, "Connect", $idConnect)
    EndIf

    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $aHandles[$g_hFTPList], -1, -1, 1, 1, 2)
        Case $idConnect
            _FTP_Connect_GUI()
        Case $idQueue
            _QueueItems($aHandles[$g_hFTPList])
        Case $idTransfer
            _QueueItems($aHandles[$g_hFTPList])
            If (UBound($gaQueue) - 1) > 0 Then
                _Statusbar(3);Transfer function will change status bar back when finished
                $aTimers[$g_tTransfer] = _Timer_SetTimer($aGUI[$g_hGUI], 500, "_Transfer")
            EndIf
        Case $idRename
            _Rename($aHandles[$g_hFTPList])
        Case $idRefresh
            _FtpRefresh(BitOR($INTERNET_FLAG_RESYNCHRONIZE,$INTERNET_FLAG_NEED_FILE))
        Case $idDelete
            _FTP_Delete()
        Case $idFolder
            Local $bMouseHover = _MouseHover_Disable()
            Local $sFolderName = InputBox('Create New Directory', 'Enter Directory Name', '', " M", Default, 130, Default, Default, 0, $aGUI[$g_hGUI])
            If Not @error Then
                _FTP_DirCreate($ghFTPConnect, $sFolderName)
                _FtpRefresh($INTERNET_FLAG_RELOAD)
            EndIf
            If $bMouseHover Then _MouseHover_Enable()
        Case $idAbort
            IniWrite($aConnectGUI[$g_sINIHistory], 'Abort', 'Abort', 1)
        Case Else
    EndSwitch
    _GUICtrlMenu_DestroyMenu($hMenu)
EndFunc   ;==>_FTPListView_RClick
Func _LocalListView_RClick()
    Local Enum $idQueue = 1000, $idTransfer, $idDelete, $idRefresh, $idFolder, $idRename, $idAbort, $idConnect
    Local $hMenu = _GUICtrlMenu_CreatePopup()
    Local $iTotalSelected = _GUICtrlListView_GetSelectedCount($aHandles[$g_hLocalList])

    If $gbFTP_Connected Then
        If $FTP_State <> $giIdle Then _GUICtrlMenu_AddMenuItem($hMenu, "ABORT Transfer", $idAbort)
        If $iTotalSelected Then
            If $FTP_State = $giIdle Then _GUICtrlMenu_AddMenuItem($hMenu, "Transfer", $idTransfer)
            _GUICtrlMenu_AddMenuItem($hMenu, "Queue", $idQueue)
        EndIf
    Else
        _GUICtrlMenu_AddMenuItem($hMenu, "Connect", $idConnect)
    EndIf
    If $iTotalSelected Then _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idDelete)
    If $iTotalSelected = 1 Then _GUICtrlMenu_AddMenuItem($hMenu, "Rename", $idRename)
    _GUICtrlMenu_AddMenuItem($hMenu, "Refresh", $idRefresh)
    If $gsLocalCurrent <> 'My Computer' Then _GUICtrlMenu_AddMenuItem($hMenu, "Create Folder", $idFolder)

    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $aHandles[$g_hLocalList], -1, -1, 1, 1, 2)
        Case $idQueue
            _QueueItems($aHandles[$g_hLocalList])
        Case $idTransfer
            _QueueItems($aHandles[$g_hLocalList])
            If (UBound($gaQueue) - 1) > 0 Then
                _Statusbar(3);Transfer function will change status bar back when finished
                $aTimers[$g_tTransfer] = _Timer_SetTimer($aGUI[$g_hGUI], 500, "_Transfer")
            EndIf
        Case $idFolder
            _Localcreatefolder()
        Case $idDelete
            _LocalDelete()
        Case $idRefresh
            If $gsLocalCurrent = 'My Computer' Then
                _MyComputer()
            Else
                _LocalGo($gsLocalCurrent)
            EndIf
        Case $idRename
            _Rename($aHandles[$g_hLocalList])
        Case $idAbort
            IniWrite($aConnectGUI[$g_sINIHistory], 'Abort', 'Abort', 1)
    EndSwitch
    _GUICtrlMenu_DestroyMenu($hMenu)
EndFunc   ;==>_LocalListView_RClick
Func _QueueListView_RClick()
    Local Enum $idTransferQueue = 4564, $idClear, $idDelete, $idAbort; $idBack;,$idFolder,$idRename
    Local $hMenu = _GUICtrlMenu_CreatePopup()
    Local $iTotalSelected = _GUICtrlListView_GetSelectedCount($aHandles[$g_hQueuelist])
    Local $iCount = _GUICtrlListView_GetItemCount($aHandles[$g_hQueuelist])

    If $gbFTP_Connected Then
        If $FTP_State = $giIdle And $iCount Then _GUICtrlMenu_AddMenuItem($hMenu, "Transfter Queue", $idTransferQueue)
        If $FTP_State <> $giIdle Then _GUICtrlMenu_AddMenuItem($hMenu, "ABORT Transfer", $idAbort)
    EndIf
    If $iCount Then _GUICtrlMenu_AddMenuItem($hMenu, "Clear Queue", $idClear)
    If $iTotalSelected Then _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idDelete)

    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $aHandles[$g_hLocalList], -1, -1, 1, 1, 2)
        Case $idTransferQueue
            _Statusbar(3)
            $aTimers[$g_tTransfer] = _Timer_SetTimer($aGUI[$g_hGUI], 500, "_Transfer")
        Case $idClear
            Global $gaQueue[1]
            _GUICtrlListView_DeleteAllItems($aHandles[$g_hQueuelist])
        Case $idDelete
            _Queue_Delete_items()
        Case $idAbort
            IniWrite($aConnectGUI[$g_sINIHistory], 'Abort', 'Abort', 1)
    EndSwitch
    _GUICtrlMenu_DestroyMenu($hMenu)
EndFunc   ;==>_QueueListView_RClick
Func _RClick_Attributes($hList, $sSection)
    Local Enum $iSize = 1, $iModified, $iAttrubute, $iCreation, $iAccess
    Local $i, $bChecked, $sKey, $hMenu = _GUICtrlMenu_CreatePopup(2)
    Local $Columns = IniReadSection($aConnectGUI[$g_sINIHistory], $sSection)

    _GUICtrlMenu_AddMenuItem($hMenu, "Size", $iSize)
    _GUICtrlMenu_AddMenuItem($hMenu, "Modifed", $iModified)
    _GUICtrlMenu_AddMenuItem($hMenu, "Attrubutes", $iAttrubute)
    _GUICtrlMenu_AddMenuItem($hMenu, "Creation", $iCreation)
    _GUICtrlMenu_AddMenuItem($hMenu, "Accessed", $iAccess)

    For $i = $iSize To $iAccess
        $bChecked = Int($Columns[$i][1]) <> 0
        _GUICtrlMenu_SetItemChecked($hMenu, $i, $bChecked, False)
    Next

    Local $mitem = _GUICtrlMenu_TrackPopupMenu($hMenu, $hList, -1, -1, 1, 1, 2)
    _GUICtrlMenu_DestroyMenu($hMenu)
    Switch $mitem
        Case $iSize
            $sKey = 'Size'
        Case $iModified
            $sKey = 'Modified'
        Case $iAttrubute
            $sKey = 'Attributes'
        Case $iCreation
            $sKey = 'Creation'
        Case $iAccess
            $sKey = 'Accessed'
        Case Else
            Return
    EndSwitch

    _SaveColumns($hList, $sSection)

    If Int($Columns[$mitem][1]) > 0 Then
        IniWrite($aConnectGUI[$g_sINIHistory], $sSection, $sKey, 0)
    Else
        IniWrite($aConnectGUI[$g_sINIHistory], $sSection, $sKey, 75)
    EndIf

    _Columns($hList, $sSection)

EndFunc   ;==>_RClick_Attributes
Func _Queue_Delete_items()
    Local $bMouseHover = _MouseHover_Disable()
    If MsgBox(36, 'Confirm Remove Items', 'Are you sure you want remove selected items from queue?', 0, $aGUI[$g_hGUI]) = 7 Then
        If $bMouseHover Then _MouseHover_Enable()
        Return
    EndIf
    Local $aSelectedQueue = _GUICtrlListView_GetSelectedIndices($aHandles[$g_hQueuelist], True)
    For $i = 1 To $aSelectedQueue[0]
        $gaQueue[$aSelectedQueue[$i] + 1] = 0
    Next
    $i = 1
    Do
        If Not $gaQueue[$i] Then
            _ArrayDelete($gaQueue, $i)
            $i -= 1
        EndIf
        $i += 1
    Until $i = UBound($gaQueue)
    _GUICtrlListView_DeleteItemsSelected($aHandles[$g_hQueuelist])
    If $bMouseHover Then _MouseHover_Enable()
EndFunc   ;==>_Queue_Delete_items
#endregion Right Click Menues............................................

#region Combobox Address Functions....................................
Func _ComboHistoryAdd(ByRef $gui_combo, ByRef $sCombo, $item)
    Local $split = StringSplit($sCombo, '|')
    _ArraySearch($split, $item)
    If Not @error Then
        GUICtrlSetData($gui_combo, $item, $item)
        Return
    EndIf
    If $split[0] > 9 Then
        _ArrayDelete($split, 1)
        $sCombo = _ArrayToString($split, '|', 1) & '|' & $item
        GUICtrlSetData($gui_combo, '', $item)
        GUICtrlSetData($gui_combo, $sCombo, $item)
    Else
        $sCombo &= '|' & $item
        GUICtrlSetData($gui_combo, $item, $item)
    EndIf
EndFunc   ;==>_ComboHistoryAdd
Func _ComboFTP_Monitor_EnterKey()
    If _IsPressed("0D", $aDll[$g_hUser32]) Then _FTPGo(GUICtrlRead($aGUI[$g_cbFTP]))
EndFunc   ;==>_ComboFTP_Monitor_EnterKey
Func _ComboLocal_Monitor_EnterKey()
    If _IsPressed("0D", $aDll[$g_hUser32]) Then
        Local $combo = GUICtrlRead($aGUI[$g_cbLocal])
        If FileExists($combo) Then
            _Push_History($gsLocalCurrent, $gaLocalHistory)
            _LocalGo($combo)
        EndIf
    EndIf
EndFunc   ;==>_ComboLocal_Monitor_EnterKey
#endregion Combobox Address Functions....................................

#region Statusbar Functions...........................................
Func _Statusbar($state)
    Switch $state
        Case 1;startup
            Local $StatusBar_PartsWidth[4] = [200, ($aGUI[$g_iWidth] / 2), ($aGUI[$g_iWidth] - 80), -1]
            Local $StatusBar_PartsText[4] = ["Not Connected", "", "", "CPU: 0.0%"]
            $aGUI[$g_hStatusBar] = _GUICtrlStatusBar_Create($aGUI[$g_hGUI], $StatusBar_PartsWidth, $StatusBar_PartsText)
            _GUICtrlStatusBar_SetMinHeight($aGUI[$g_hStatusBar], 21)
        Case 2;connected
            _GUICtrlStatusBar_Destroy($aGUI[$g_hStatusBar])
            Local $StatusBar_PartsWidth[4] = [200, ($aGUI[$g_iWidth] / 2), ($aGUI[$g_iWidth] - 80), -1]
            Local $StatusBar_PartsText[4] = ['Connected IP : ' & $gsServer_IP, $gsServer_Name, "Idle (00:00)", $CPU]
            $aGUI[$g_hStatusBar] = _GUICtrlStatusBar_Create($aGUI[$g_hGUI], $StatusBar_PartsWidth, $StatusBar_PartsText);Connection, idle, messeges?
            _GUICtrlStatusBar_SetMinHeight($aGUI[$g_hStatusBar], 21)
            $aTimers[$g_tIdleClock] = TimerInit()
            $aTimers[$g_bIdleClock] = True
        Case 3;Transfer
            Local $FileNameLen
            $aTimers[$g_bIdleClock] = False
            _GUICtrlStatusBar_Destroy($aGUI[$g_hStatusBar])
            If ($aGUI[$g_iWidth] / 2) > 480 Then
                $FileNameLen = ($aGUI[$g_iWidth] / 2)
            Else
                $FileNameLen = $aGUI[$g_iWidth] - 580 ; ;[75, ?,  80,  80,  80, 140, 200]
            EndIf
            Local $StatusBar_PartsWidth[7] = [75, $FileNameLen, $FileNameLen + 80, $FileNameLen + 160, $FileNameLen + 240, $FileNameLen + 380, -1]
            Local $StatusBar_PartsText[7] = ["Idle:", 'FileName', $CPU, 'Time (00:00)', '', '', '']
            $aGUI[$g_hStatusBar] = _GUICtrlStatusBar_Create($aGUI[$g_hGUI], $StatusBar_PartsWidth, $StatusBar_PartsText);Uploading or Downloading, filename, speed, Estimated Time
            _GUICtrlStatusBar_SetMinHeight($aGUI[$g_hStatusBar], 21)
            $aGUI[$g_hProgressBar] = GUICtrlCreateProgress(0, 0, -1, -1, $PBS_SMOOTH)
            _GUICtrlStatusBar_EmbedControl($aGUI[$g_hStatusBar], 6, GUICtrlGetHandle($aGUI[$g_hProgressBar]), 4)
    EndSwitch
EndFunc   ;==>_Statusbar
Func _CPU_IdleClock_Update($hWnd, $Msg, $iIDTimer, $dwTime)

    Static $StartTimes[2], $EndTimes[2], $bFirstRun = True
    Static $CPU_Kernel = DllStructCreate($tagFileTime), $CPU_User = DllStructCreate($tagFileTime), $CPU_Idle = DllStructCreate($tagFileTime)
    Static $pCPU_Kernel = DllStructGetPtr($CPU_Kernel), $pCPU_User = DllStructGetPtr($CPU_User), $pCPU_Idle = DllStructGetPtr($CPU_Idle)

    DllCall($aDll[$g_hKernel32], "int", "GetSystemTimes", "ptr", $pCPU_Idle, "ptr", $pCPU_Kernel, "ptr", $pCPU_User)
    $EndTimes[0] = (DllStructGetData($CPU_Kernel, 1) + DllStructGetData($CPU_User, 1)); Kerneltime + UserTime
    $EndTimes[1] = DllStructGetData($CPU_Idle, 1);IdleTime

    If $bFirstRun Then
        $StartTimes = $EndTimes
        $bFirstRun = False
        Return
    EndIf

    Local $Idle_Time = $EndTimes[1] - $StartTimes[1]
    If $Idle_Time > 0 Then ; Every once in a while idle time will be negative because the 32bit value gets to high and goes back to zero causing starttime to be bigger then endtime
        Local $Total_Time = $EndTimes[0] - $StartTimes[0]
        Local $CPU_Percent = (($Total_Time - $Idle_Time) / $Total_Time) * 100
        $CPU_Percent = StringFormat('CPU: %.1f%%', $CPU_Percent)
        If $CPU <> $CPU_Percent Then
            If $FTP_State = $giIdle Then
                _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], $CPU_Percent, 3)
            Else
                _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], $CPU_Percent, 2)
            EndIf
            $CPU = $CPU_Percent
        EndIf
    EndIf
    $StartTimes = $EndTimes

    If $aTimers[$g_bIdleClock] Then
        Local $Hour, $Mins, $Secs
        _TicksToTime(Int(TimerDiff($aTimers[$g_tIdleClock])), $Hour, $Mins, $Secs)
        If Not $Hour Then
            _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], StringFormat("Idle (%02i:%02i)", $Mins, $Secs), 2)
        Else
            _GUICtrlStatusBar_SetText($aGUI[$g_hStatusBar], StringFormat("Idle (%02i:%02i:%02i)", $Hour, $Mins, $Secs), 2)
        EndIf
    EndIf

EndFunc   ;==>_CPU_IdleClock_Update
#endregion Statusbar Functions...........................................
#region History Stack Functions.......................................
Func _Push_History($item, ByRef $aHistory)
    If $aHistory[0] = $item Then Return
    For $i = 19 To 1 Step -1
        $aHistory[$i] = $aHistory[$i - 1]
    Next
    $aHistory[0] = $item
EndFunc   ;==>_Push_History
Func _Pop_History(ByRef $aHistory, $iNoDelete = True)
    If Not $iNoDelete Then Return $aHistory[0]
    Local $pop = $aHistory[0]
    For $i = 0 To 18
        $aHistory[$i] = $aHistory[$i + 1]
    Next
    $aHistory[19] = ''
    Return $pop
EndFunc   ;==>_Pop_History
#endregion History Stack Functions.......................................
#region Other Functions...............................................
Func _ExitTime()
    _SaveColumns($aHandles[$g_hFTPList], 'FTPColumns')
    _SaveColumns($aHandles[$g_hLocalList], 'LocalColumns')
    _GUICtrlRichEdit_Destroy($aGUI[$g_StatusList])
    IniWrite($aConnectGUI[$g_sINIHistory], "Abort", "Abort", 0)
    _Timer_KillAllTimers($aGUI[$g_hGUI])
    For $i = 0 To UBound($aDll) - 1
        DllClose($aDll[$i])
    Next
    If @Compiled Then FileDelete($g_sWorker)
EndFunc   ;==>_ExitTime
Func _ListSetFocus($CtrlID)
    If Not $aGUI[$g_bActive] Then Return
    If $CtrlID = $aGUI[$g_StatusList] Then
        ConsoleWrite('statuslist' & @CRLF)
        If Not _WinAPI_SetFocus($aGUI[$g_StatusList]) Then ConsoleWrite('statusfocus error' & @CRLF)
        Return
    EndIf
    GUICtrlSetState($CtrlID, $GUI_FOCUS)
EndFunc   ;==>_ListSetFocus
Func _bytes($iBytes)
    Switch $iBytes
        Case 0 To 1023
            Return $iBytes & " Bytes"
        Case 1024 To 1048575
            Return Round($iBytes / 1024, 2) & " KB"
        Case 1048576 To 1073741823
            Return Round($iBytes / 1048576, 2) & " MB"
        Case Else
            Return Round($iBytes / 1073741824, 2) & " GB"
    EndSwitch
EndFunc   ;==>_bytes
Func _ArraytoConsole($array, $name = '')
    Local $i, $string = $name & @CRLF
    For $i = 0 To UBound($array) - 1
        $string &= '[' & $i & ']' & $array[$i] & @CRLF
    Next
    ConsoleWrite($string)
EndFunc   ;==>_ArraytoConsole
Func _RichEdit_AppendColor($sMsg, $iColor = 0, $bCRLF = False)
    _CheckLen()

    _GUICtrlRichEdit_Deselect($aGUI[$g_StatusList])
    _GUICtrlRichEdit_GotoCharPos($aGUI[$g_StatusList], -1)
    Local $FirstCharPos = _GUICtrlRichEdit_GetFirstCharPosOnLine($aGUI[$g_StatusList])
    _GUICtrlRichEdit_SetSel($aGUI[$g_StatusList], $FirstCharPos, $FirstCharPos + 1)
    Local $StartPOS = $FirstCharPos + _GUICtrlRichEdit_GetLineLength($aGUI[$g_StatusList], -1)

    _GUICtrlRichEdit_AppendText($aGUI[$g_StatusList], $sMsg)
    _GUICtrlRichEdit_SetSel($aGUI[$g_StatusList], $StartPOS, -1, True)
    _GUICtrlRichEdit_SetCharColor($aGUI[$g_StatusList], $iColor)
    _GUICtrlRichEdit_Deselect($aGUI[$g_StatusList])

    If $bCRLF Then _GUICtrlRichEdit_AppendText($aGUI[$g_StatusList], @CRLF)

EndFunc   ;==>_RichEdit_AppendColor
Func _CheckLen()
    Static $iCount
    $iCount += 1
    If $iCount <= 50 Then Return
    If _GUICtrlRichEdit_GetTextLength($aGUI[$g_StatusList], False, True) > 90000 Then
        _GUICtrlRichEdit_SetSel($aGUI[$g_StatusList], 0, 30000)
        _GUICtrlRichEdit_ReplaceText($aGUI[$g_StatusList], "")
    EndIf
    $iCount = 0
EndFunc   ;==>_CheckLen
Func _Resize_Rich_Edit()
    Local $FTP_POS = ControlGetPos($aGUI[$g_sTitle], '', $aGUI[$g_FTPList])
    Local $Queue_POS = ControlGetPos($aGUI[$g_sTitle], '', $aGUI[$g_QueueList])
    _WinAPI_SetWindowPos($aGUI[$g_StatusList], 0, $FTP_POS[0], $Queue_POS[1], $Queue_POS[2], $Queue_POS[3], $SWP_SHOWWINDOW)
EndFunc   ;==>_Resize_Rich_Edit
Func _Speed($size, $millsec)
    Local $speed = $size / ($millsec / 1000)
    If $speed >= 1048576 Then Return Round($speed / 1048576, 2) & " mB/sec"
    Return Round($speed / 1024, 2) & " kB/sec"
EndFunc   ;==>_Speed
Func _Format_Time($iMillseconds)
    $iMillseconds = Int($iMillseconds)
    If $iMillseconds < 60000 Then Return Round($iMillseconds / 1000, 2)
    Local $Hour, $Mins, $Secs
    If $iMillseconds < 3600000 Then
        _TicksToTime($iMillseconds, $Hour, $Mins, $Secs)
        Return StringFormat("%02i:%02i", $Mins, $Secs)
    Else
        _TicksToTime($iMillseconds, $Hour, $Mins, $Secs)
        Return StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
    EndIf
EndFunc   ;==>_Format_Time
Func _FileListToArray_mod($sPath, $sFilter = "*", $iFlag = 0)
    Local $hSearch, $sFile, $sFileList, $sFolderList, $sDelim = "|"
    $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "") & "\" ; ensure single trailing backslash
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, "[\\/:><\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
    $hSearch = FileFindFirstFile($sPath & $sFilter)
    If @error Then Return SetError(4, 4, "")
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If @extended Then
            $sFolderList &= $sDelim & $sFile
        Else
            $sFileList &= $sDelim & $sFile
        EndIf
    WEnd
    FileClose($hSearch)
    $sFileList = $sFolderList & $sFileList
    If Not $sFileList Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimLeft($sFileList, 1), "|")
EndFunc   ;==>_FileListToArray_mod
Func _Rename($hHandle)
    Local $aSelected = _GUICtrlListView_GetSelectedIndices($hHandle, True)
    Local $sFileName = _GUICtrlListView_GetItemText($hHandle, $aSelected[1], 0)
    Local $bMouseHover = _MouseHover_Disable()
    Local $sNewName = InputBox("Rename File", "Enter New File Name:", $sFileName, " M", Default, 130, Default, Default, 0, $aGUI[$g_hGUI])
    If @error Then
        If $bMouseHover Then _MouseHover_Enable()
        Return
    EndIf
    Switch $hHandle
        Case $aHandles[$g_hFTPList]
            _FTP_FileRename($ghFTPConnect, $sFileName, $sNewName)
            _FtpRefresh($INTERNET_FLAG_RELOAD)
        Case $aHandles[$g_hLocalList]
            FileMove($gsLocalCurrent & '\' & $sFileName, $gsLocalCurrent & '\' & $sNewName)
            _LocalGo($gsLocalCurrent);refresh
    EndSwitch
    If $bMouseHover Then _MouseHover_Enable()
EndFunc   ;==>_Rename
Func _Check_INI_File()
    If Not FileExists($aConnectGUI[$g_sINIHistory]) Then
        _FileCreate($aConnectGUI[$g_sINIHistory])
        IniWrite($aConnectGUI[$g_sINIHistory], "Abort", "Abort", 0)
        Local $aLast[4][2] = [["User", ''],["Pass", ''],["Port", '21'],["IP", '']]
        IniWriteSection($aConnectGUI[$g_sINIHistory], 'Last', $aLast, 0)
        Local $aColumns[6][2] = [["Size", '75'],["Modified", '0'],["Attributes", '0'],["Creation", '0'],["Accessed", '0'],["File", '350']]
        IniWriteSection($aConnectGUI[$g_sINIHistory], 'FTPColumns', $aColumns, 0)
        IniWriteSection($aConnectGUI[$g_sINIHistory], 'LocalColumns', $aColumns, 0)
    EndIf
EndFunc   ;==>_Check_INI_File
Func _ReduceMemory()
    If $FTP_State = $giIdle Then
;~      _ArraytoConsole(MemGetStats())
        DllCall($aDll[$g_hPSAPI], 'int', 'EmptyWorkingSet', 'long', -1)
        If @error Then ConsoleWrite('error code = ' & @error & @CRLF)
;~      ConsoleWrite('release' & @CRLF)
;~      _ArraytoConsole(MemGetStats())
    EndIf
EndFunc   ;==>_ReduceMemory
#endregion Other Functions...............................................
#region Functions not written by me...................................
;Prog@ndy Icon Functions...................................
Func _GUIImageList_GetSystemImageList($bLargeIcons = False)
    Local $SHGFI_USEFILEATTRIBUTES = 0x10, $SHGFI_SYSICONINDEX = 0x4000, $SHGFI_SMALLICON = 0x1;, $SHGFI_LARGEICON = 0x0;,$FILE_ATTRIBUTE_NORMAL = 0x80
    Local $FileInfo = DllStructCreate("dword hIcon; int iIcon; DWORD dwAttributes; CHAR szDisplayName[255]; CHAR szTypeName[80];")
    Local $dwFlags = BitOR($SHGFI_USEFILEATTRIBUTES, $SHGFI_SYSICONINDEX)
    If Not ($bLargeIcons) Then $dwFlags = BitOR($dwFlags, $SHGFI_SMALLICON)
    Local $hIml = _WinAPI_SHGetFileInfo(".txt", $FILE_ATTRIBUTE_NORMAL, DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), $dwFlags)
    Return $hIml
EndFunc   ;==>_GUIImageList_GetSystemImageList
Func _GUIImageList_GetFileIconIndex($sFileSpec, $bLargeIcons = False, $bForceLoadFromDisk = False);modified
    Static $FileInfo = DllStructCreate("dword hIcon; int iIcon; DWORD dwAttributes; CHAR szDisplayName[255]; CHAR szTypeName[80];")
    Local $dwFlags = BitOR(0x4000, 0x1)
    If Not $bForceLoadFromDisk Then $dwFlags = BitOR($dwFlags, 0x10)
    DllCall($aDll[$g_hShell32], "DWORD*", "SHGetFileInfo", "str", $sFileSpec, "DWORD", $FILE_ATTRIBUTE_NORMAL, "ptr", DllStructGetPtr($FileInfo), _
            "UINT", DllStructGetSize($FileInfo), "UINT", $dwFlags)
    If @error Then Return SetError(1, 0, -1)
    Return DllStructGetData($FileInfo, "iIcon")
EndFunc   ;==>_GUIImageList_GetFileIconIndex
Func _WinAPI_SHGetFileInfo($pszPath, $dwFileAttributes, $psfi, $cbFileInfo, $uFlags)
    Local $return = DllCall($aDll[$g_hShell32], "DWORD*", "SHGetFileInfo", "str", $pszPath, "DWORD", $dwFileAttributes, "ptr", $psfi, "UINT", $cbFileInfo, "UINT", $uFlags)
    If @error Then Return SetError(@error, 0, 0)
    Return $return[0]
EndFunc   ;==>_WinAPI_SHGetFileInfo

; #FUNCTION# ===============================
; Author(s):        Yashied
;====================================================================================================================================
Func _InternetSetOption($hInternet, $lOption, $lValue)
    Local Const $tagINTERNET_PROXY_INFO = 'dword AccessType;ptr Proxy;ptr ProxyBypass;';internet options
    Local $Ret, $Back, $tBuffer
    Switch $lOption
        Case 2, 3, 5, 6, 12, 13
            If IsInt($lValue) Then $tBuffer = DllStructCreate('int')
        Case 28, 29, 41
            If IsString($lValue) Then $tBuffer = DllStructCreate('char[' & StringLen($lValue) + 1 & ']')
        Case 38
            If IsDllStruct($lValue) Then $tBuffer = DllStructCreate($tagINTERNET_PROXY_INFO, DllStructGetPtr($lValue))
        Case 45
            If IsPtr($lValue) Then $tBuffer = DllStructCreate('ptr')
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
    If Not ($lOption = 38) Then DllStructSetData($tBuffer, 1, $lValue)
    $Back = _InternetGetOption($hInternet, $lOption)
    If (@error) Then Return SetError(1, @extended, 0)
    $Ret = DllCall('wininet.dll', 'int', 'InternetSetOption', 'hwnd', $hInternet, 'dword', $lOption, 'ptr', DllStructGetPtr($tBuffer), 'dword', DllStructGetSize($tBuffer))
    If (@error) Or ($Ret[0] = 0) Then Return SetError(1, _WinAPI_GetLastError(), 0)
    Return SetError(0, 0, $Back)
EndFunc   ;==>_InternetSetOption
Func _InternetGetOption($hInternet, $lOption)
    Local Const $tagINTERNET_PROXY_INFO = 'dword AccessType;ptr Proxy;ptr ProxyBypass;';internet options
    Local $Ret, $tBuffer
    Switch $lOption
        Case 2, 3, 5, 6, 12, 13
            $tBuffer = DllStructCreate('int')
        Case 28, 29, 41
            $tBuffer = DllStructCreate('char[1024]')
        Case 38
            $tBuffer = DllStructCreate($tagINTERNET_PROXY_INFO)
        Case 45
            $tBuffer = DllStructCreate('ptr')
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
    $Ret = DllCall('wininet.dll', 'int', 'InternetQueryOption', 'hwnd', $hInternet, 'dword', $lOption, 'ptr', DllStructGetPtr($tBuffer), 'dword*', DllStructGetSize($tBuffer))
    If (@error) Or ($Ret[0] = 0) Then Return SetError(1, _WinAPI_GetLastError(), 0)
    Switch $lOption
        Case 38
            Return SetError(0, 0, $tBuffer)
        Case Else
            Return SetError(0, 0, DllStructGetData($tBuffer, 1))
    EndSwitch
EndFunc   ;==>_InternetGetOption
Func _About($Title, $MainLabel, $CopyRLabel, $VerLabel, $NameURL1, $URL1, $NameURL2, $URL2, $NameURL3, $URL3, $IconFile = "", $LinkColor = 0x0000FF, $BkColor = 0xFFFFFF, $Left = -1, $Top = -1, $Style = -1, $ExStyle = -1, $Parent = 0)
    Local $OldEventOpt = Opt("GUIOnEventMode", 0)
    Local $GUI_About, $LinkTop = 120, $Msg, $CurIsOnCtrlArr[1]
    Local $LinkVisitedColor[4] = [3, $LinkColor, $LinkColor, $LinkColor], $LinkLabel[4]
    WinSetState($Parent, "", @SW_DISABLE)

    If $ExStyle = -1 Then $ExStyle = ""
    $GUI_About = GUICreate($Title, 320, 240, $Left, $Top, $Style, 0x00000080 + $ExStyle, $Parent)
    GUISwitch($GUI_About)
    GUISetBkColor($BkColor)
    GUICtrlCreateLabel($MainLabel, 40, 20, 280, 25, 1)
    GUICtrlSetFont(-1, 16)
    GUICtrlCreateIcon($IconFile, 0, 10, 20)
    GUICtrlCreateGraphic(5, 75, 310, 3, $SS_ETCHEDFRAME)
    For $i = 1 To 3
        $LinkLabel[$i] = GUICtrlCreateLabel(Eval("NameURL" & $i), 150, $LinkTop, 145, 15, 1)
        GUICtrlSetCursor(-1, 0)
        GUICtrlSetColor(-1, $LinkColor)
        GUICtrlSetFont(-1, 9, 400, 0)
        $LinkTop += 30
    Next
    GUICtrlCreateLabel("Program version: " & @LF & $VerLabel, 10, 130, 150, 35, 1)
    GUICtrlSetFont(-1, 10, 600, 0, "Tahoma")
    GUICtrlCreateLabel($CopyRLabel, 0, 220, 320, -1, 1)
    GUISetState(@SW_SHOW, $GUI_About)

    While 1
        $Msg = GUIGetMsg()
        If $Msg = -3 Then ExitLoop
        For $i = 1 To 3
            If $Msg = $LinkLabel[$i] Then
                $LinkVisitedColor[$i] = 0xAC00A9
                GUICtrlSetColor($LinkLabel[$i], $LinkVisitedColor[$i])
                ShellExecute(Eval("URL" & $i))
            EndIf
        Next
        If WinActive($aGUI[$g_hGUI]) Then
            For $i = 1 To 3
                ControlHover($GUI_About, $LinkLabel[$i], $i, $CurIsOnCtrlArr, 0xFF0000, $LinkVisitedColor[$i])
            Next
        EndIf
    WEnd
    WinSetState($Parent, "", @SW_ENABLE)
    GUIDelete($GUI_About)
    GUISwitch($aGUI[$g_hGUI])
    Opt("GUIOnEventMode", $OldEventOpt)
EndFunc   ;==>_About
Func ControlHover($hWnd, $CtrlID, $CtrlNum, ByRef $CurIsOnCtrlArr, $HoverColor = 0xFF0000, $LinkColor = 0x0000FF)
    Local $CursorCtrl = GUIGetCursorInfo($hWnd)
    ReDim $CurIsOnCtrlArr[UBound($CurIsOnCtrlArr) + 1]
    If $CursorCtrl[4] = $CtrlID And $CurIsOnCtrlArr[$CtrlNum] = 1 Then
        GUICtrlSetFont($CtrlID, 9, 400, 6)
        GUICtrlSetColor($CtrlID, $HoverColor)
        $CurIsOnCtrlArr[$CtrlNum] = 0
    ElseIf $CursorCtrl[4] <> $CtrlID And $CurIsOnCtrlArr[$CtrlNum] = 0 Then
        GUICtrlSetFont($CtrlID, 9, 400, 0)
        GUICtrlSetColor($CtrlID, $LinkColor)
        $CurIsOnCtrlArr[$CtrlNum] = 1
    EndIf
EndFunc   ;==>ControlHover
#endregion Functions not written by me...................................
;

I'm needing it to work with GUIOnEventMode, is there a simpler way to accomplish this?

 

Edit:

Here's what I have so far:

#include <FTPEx.au3>
#NoTrayIcon
#include <GUIListBox.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

$MAIN = GUICreate("main", 400, 400, -1, -1)
Local $server = ''
Local $username = ''
Local $pass = ''
Local $Open = _FTP_Open('')
Local $Conn = _FTP_Connect($Open, $server, $username, $pass)
Local $aFile = _FTP_ListToArray($Conn, 1)
$List1 = GUICtrlCreateList("", 24, 22, 343, 325)
GuiCtrlSetData($List1, "|{ ... }|" &_ArrayToString($aFile, "|", 1))
Local $Ftpc = _FTP_Close($Open)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

EndSwitch
Sleep(10)
WEnd
Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#RequireAdmin
#include <Misc.au3>
#include <FTPEx.au3>
OnAutoItExitRegister("_mexit")
Local $Open = _FTP_Open('MyFTP Control')
if @error Then Exit 1
MsgBox(0,$open,$open&@CRLF&VarGetType($open))
Local $server="ftp.orange.com"
Local $username="elma"
Local $pass="armut"
Local $connect =_FTP_Connect($open,$server,$username,$pass)
if @error Then Exit 2
Local $localfile=(@ScriptDir&"\myftp.txt")

Local $remloc=("/root/Dhcp/myftp.txt")
_FTP_FilePut($connect,$localfile,$remloc)
if @error Then Exit 3
$remotefile="msyftpfiledir"
$fo=_FTP_FileOpen($connect,@ScriptDir&"/root/Dhcp/myftp.txt")
if @error Then Exit 4
$read=_FTP_FileRead($fo,1)
if @error Then Exit 5
ConsoleWrite("the read is:")
ConsoleWrite($read)
While 1
if _IsPressed("4b")  Then ExitLoop
    WEnd
Func _mexit()
Local $discon = _FTP_Close($connect)
Local $Ftpc = _FTP_Close($Open)
ConsoleWrite("The error code is:"&@error&"<==")
EndFunc

why the _ftp_connect code give an eror please tell me which variable is wrong. :puke: 

Please enlighten  me about this subject. :ILA:

Edited by nomadman

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