Sign in to follow this  
Followers 0
Beege

FTP Downloader / Explorer with Progress

3 posts in this topic

#1 ·  Posted (edited)

So this is just a start but it works so far. There are a couple of bugs in the progress bars but not to bad. The explorer is uses _GUILVSort7.au3 so that you can doubleclick on a directory and navigate to it. Download with progress does work and it also works for downloading full folders. Just check the boxes and click download. I would love anybody to look at the uploading file function i started. Its driving me crazy. I know its possible and im just missing something stupid. I have rewritten it a thousand times and still nothing!! The zip file included should have everything need to run the script so let me know if it wont work.

#include <GUIConstants.au3>
#include <GuiListView.au3>
#Include <GuiList.au3>
#include <array.au3>
#include <file.au3>
#include <math.au3>
#include "_GUILVSort7.au3"
#include "FTP.au3"
#include "API.au3"

Global Const $INTERNET_FLAG_EXISTING_CONNECT = 0x20000000
Global Const $INTERNET_FLAG_PASSIVE = 0x08000000
Global Const $INTERNET_FLAG_TRANSFER_ASCII = 0x00000001
Global Const $INTERNET_FLAG_TRANSFER_BINARY = 0x00000002
Global Const $INTERNET_FLAG_NEED_FILE = 0x00000010
Global Const $INTERNET_DEFAULT_FTP_PORT = 21
Global Const $INTERNET_SERVICE_FTP = 1
Global Const $INTERNET_FLAG_MAKE_PERSISTENT = 0x02000000
Global Const $INTERNET_FLAG_RESYNCHRONIZE = 0x00000800
Global Const $INTERNET_FLAG_RELOAD = 0x80000000
Global Const $INTERNET_FLAG_HYPERLINK = 0x00000400
Global Const $INTERNET_FLAG_DONT_CACHE = 0x04000000
Global Const $FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x0100
Global Const $FORMAT_MESSAGE_IGNORE_INSERTS = 0x0200
Global Const $FORMAT_MESSAGE_FROM_STRING = 0x0400
Global Const $FORMAT_MESSAGE_FROM_HMODULE = 0x0800
Global Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x1000
Global Const $FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x2000
Global $hList, $LastDir, $size, $download, $TTime, $Total_Bytes_Read, $TdFiles, $download_List, $TotaldFiles, _
        $dirs, $Total_Size, $Total_Bytes, $mdsize, $mdbytes_read, $md_Time, $Total_Files, $Total_Dirs, $bytes, $regIP, _
        $regPass, $regUser, $deleted, $connected, $FTPconnect, $dlist, $ipchange = 0, $maxdword = (2 ^ 32) - 1, $currentdir = ''
Global $cache, $cachedata, $cacheNames
_RecentConnections()

$hGUI = GUICreate("~Beege~ FTP Navigator", 549, 387, 244, 205, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
$wininet = DllOpen('wininet.dll')
_GUISetCheckBoxesPresent ($hGUI, $hList, 1, 1, 7)
$hList = _GUICtrlCreateListViewIndexed ("File   |size |Bytes", 16, 8, 297, 225, $LVS_EX_GRIDLINES, BitOR($LVS_EX_GRIDLINES, $LVS_EX_HEADERDRAGDROP, $LVS_EX_FULLROWSELECT, $LVS_EX_REGIONAL));Drag&Drop Column
_GUICtrlListViewSetColumnWidth($hList, 0, 225)
_GUICtrlListViewSetColumnWidth($hList, 1, 60)
_GUICtrlListViewSetColumnWidth($hList, 2, 0)
_GUICtrlListViewSetColumnWidth($hList, 3, 0)
_GUICtrlListViewSetColumnWidth($hList, 4, 0)

$IP = GUICtrlCreateInput($regIP, 400, 40, 105, 21)
GUICtrlCreateLabel("", 72, 320, 4, 4)
GUICtrlCreateLabel("Files :", 16, 240, 31, 17)
$tfiles = GUICtrlCreateLabel("", 48, 240, 52, 17)
GUICtrlCreateLabel("Total Size :", 200, 240, 57, 17)
$tsize = GUICtrlCreateLabel("", 256, 240, 64, 17)
$Progress1 = GUICtrlCreateProgress(16, 272, 513, 17)
$Progress2 = GUICtrlCreateProgress(16, 320, 513, 17)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
GUICtrlCreateLabel("Current File :", 16, 296, 63, 17)
$currentfile = GUICtrlCreateLabel("", 80, 296, 4, 4)
$checkall = GUICtrlCreateButton("Check All", 328, 168, 83, 25, 0)
$Uncheckall = GUICtrlCreateButton("Uncheck All", 328, 200, 83, 25, 0)
$Back = GUICtrlCreateButton("Back", 328, 136, 81, 25, 0)
$Userbox = GUICtrlCreateInput($regUser, 400, 72, 105, 21)
$Passbox = GUICtrlCreateInput($regPass, 400, 104, 105, 21)
GUICtrlCreateLabel("Server Address", 320, 40, 76, 17, $SS_RIGHT)
GUICtrlCreateLabel("User Name", 336, 72, 57, 17, $SS_RIGHT)
GUICtrlCreateLabel("Password", 344, 104, 50, 17, $SS_RIGHT)
$Upload_files = GUICtrlCreateButton("Upload Files", 432, 168, 83, 25, 0)
$Pause = GUICtrlCreateButton("Pause", 432, 200, 83, 25, 0)
$download = GUICtrlCreateButton("Download", 432, 136, 81, 25, 0)
GUICtrlCreateLabel("Dirs :", 112, 240, 28, 17)
$tdirs = GUICtrlCreateLabel("", 144, 240, 58, 17)
$file_status = GUICtrlCreateLabel("", 80, 296, 450, 17)
$Connect = GUICtrlCreateButton("Connect", 328, 8, 81, 25, 0)
$exit = GUICtrlCreateButton("Exit", 432, 8, 81, 25, 0)
$Rename = GUICtrlCreateButton("Rename", 328, 232, 83, 25, 0)
$Delete = GUICtrlCreateButton("Delete", 432, 232, 83, 25, 0)
$Total_Progress = GUICtrlCreateLabel("", 96, 344, 436, 17)
GUICtrlCreateLabel("Total Progress:", 16, 344, 71, 17)
GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()
    _GetLVInfo ($msg)
    Sleep(10)
    Select
        Case $msg = $Connect
            $ipsafe = _CheckIP(GUICtrlRead($IP))
            GUICtrlSetData($IP, $ipsafe)
            $FTPconnect = _connect()
            If $FTPconnect = 0 Then ContinueLoop
            $LastDir = _FTPGetCurrentDir($FTPconnect)
            _GetList()
        Case $msg = $Back
            $Current_Directory = _FTPGetCurrentDir($FTPconnect)
            If $Current_Directory = '/' Then ContinueLoop
            $LastDir = StringReplace(StringLeft($LastDir, StringInStr($LastDir, '/', 0, -2)), '//', '/')
            _FtpSetCurrentDir($FTPconnect, $LastDir)
            _GetList()
        Case $msg = $Uncheckall
            $ret = _GUICtrlListViewSetCheckState($hList, -1, 0)
        Case $msg = $checkall
            $ret = _GUICtrlListViewSetCheckState($hList, -1, 1)
        Case $msg = $download
            $TTime = TimerInit()
            $Total_Size = 0
            $dirs = 0
            $TotaldFiles = 1
            $savedir = FileSelectFolder("Choose a folder.", "", 5, @ScriptDir)
            ;$savedir = 'c:\test'
            If @error = 1 Then ContinueLoop
            $cur1 = _FTPGetCurrentDir($FTPconnect)
            $cur = StringTrimLeft($cur1, StringInStr($cur1, '/', 2, -1))
            $download_List = _Get_Download_List()
            For $i = 1 To $download_List[0]
                If StringLeft($download_List[$i], 1) = '$' Then
                    $dirs = $dirs + 1
                    ContinueLoop
                EndIf
                $split = StringSplit($download_List[$i], '|')
                _ArrayAdd($download, $split[1])
                $Total_Size = $Total_Size + $split[2]
                $TotaldFiles = $TotaldFiles + 1
            Next
            ;_ArrayDisplay($download_List, _Bytes_Convert($Total_Size) & '   |   ' & $TotaldFiles & '   |   ' & $dirs)
            For $i = 1 To UBound($download_List) - 1
                If StringLeft($download_List[$i], 1) = '$' Then
                    _FtpSetCurrentDir($FTPconnect, StringTrimLeft($download_List[$i], 1))
                    $replace = StringReplace(StringTrimLeft(StringReplace($download_List[$i], $cur1, ''), 2), '/', '\')
                    $check = $savedir & '\' & StringTrimRight($replace, 1)
                    If Not FileExists($check) Then DirCreate($check)
                    ContinueLoop
                EndIf
                $split = StringSplit($download_List[$i], '|')
                $mdftpfile = StringTrimLeft($split[1], StringInStr($split[1], '/', 2, -1))
                $mdLocal_Dir_file = StringReplace(StringReplace($split[1], $cur1 & '/', ''), '/', '\')
                _FTPDownloadFile($FTPconnect, $Progress1, $file_status, $mdftpfile, $split[2], $savedir & '\' & $mdLocal_Dir_file)
                $TdFiles = $TdFiles + 1
            Next
        Case $msg = $exit
            ExitLoop
        Case $msg = $Rename
            $selected = _GUICtrlListViewGetCurSel($hList)
            $name = _GUICtrlListViewGetItemTextArray($hList, $selected)
            $box = InputBox('Rename File', '', $name[1])
            If @error Then ContinueCase
            _FTPRenameFile ($FTPconnect, $name[1], $box)
            _GetList()
            _GUICtrlListViewSetItemSelState($hList, $selected, 1, 0)
        Case $msg = $Delete
            $deleted = 0
            For $i = 0 To _GUICtrlListViewGetItemCount($hList) - 1
                $is_Checked = _GUICtrlListViewGetCheckedState($hList, $i)
                If $is_Checked = 1 Then
                    $deleted = $deleted + 1
                    $checked = _GUICtrlListViewGetItemTextArray($hList, $i)
                    _FTPDelFile ($FTPconnect, $checked[1])
                EndIf
            Next
            If $deleted = 0 Then ContinueLoop
            _GetList()
        Case $msg = $Pause
        Case $msg = $Upload_files
    EndSelect
Until $msg = $GUI_EVENT_CLOSE
DllClose($wininet)
If $connected = 1 Then _FTPClose ($FTPconnect)
Exit

;My Functions
Func _CheckIP($IP)
    $ipcheck = StringReplace($IP, '.', '')
    If StringIsDigit($ipcheck) Then
        Return $IP
    Else
        TCPStartup()
        $newip = TCPNameToIP($IP)
        TCPShutdown()
        $ipchange = $IP
        Return $newip
    EndIf
EndFunc   ;==>_CheckIP

Func _RecentConnections()
    $regIP = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "IP")
    If @error Then
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "IP", "REG_SZ", "ftp.ch.freebsd.org")
        $regIP = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "IP")
    EndIf
    $regUser = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "User")
    If @error Then
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "IP", "REG_SZ", "")
        $regUser = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "User")
    EndIf
    $regPass = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "Pass")
    If @error Then
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "IP", "REG_SZ", "")
        $regPass = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "Pass")
    EndIf
EndFunc   ;==>_RecentConnections

Func _GetList()
    _GUICtrlListViewDeleteAllItems($hList)
    Local $bytes = 0
    $FolderList = _FTPFiles_and_Sizes_ListtoArray($FTPconnect, 1, $INTERNET_FLAG_RESYNCHRONIZE)
    If Not IsArray($FolderList) Then
        $nItem = GUICtrlCreateListViewItem('No Items in Directory', $hList)
        Return 0
    EndIf
    _ArraySort($FolderList, 0, 1)
    For $i = 1 To $FolderList[0]
        $nItem = GUICtrlCreateListViewItem($FolderList[$i] & '|DIR', $hList)
    Next
    GUICtrlSetData($tdirs, $FolderList[0])
    $FileList = _FTPFiles_and_Sizes_ListtoArray($FTPconnect, 2, $INTERNET_FLAG_RESYNCHRONIZE)
    _ArraySort($FileList, 0, 1)
    For $i = 1 To $FileList[0]
        $size = StringSplit($FileList[$i], '|')
        If $size[2] = -1 Then $size[2] = (_FTPGetFileSize($FTPconnect, $size[1]) + $maxdword)
        $nItem = GUICtrlCreateListViewItem($size[1] & '|' & _Bytes_Convert($size[2]) & '|' & $size[2], $hList)
        $bytes = $bytes + $size[2]
        GUICtrlSetData($tsize, _Bytes_Convert($bytes))
    Next
    GUICtrlSetData($tfiles, $FileList[0])
    _GUICtrlListViewSetColumnWidth($hList, 2, 0)
    Return 0
EndFunc   ;==>_GetList

Func _connect()
    _GUICtrlListViewDeleteAllItems($hList)
    $XBOX = _FTPOpen ('XBOX')
    $conn = _FTPConnect ($XBOX, GUICtrlRead($IP), GUICtrlRead($Userbox), GUICtrlRead($Passbox), $INTERNET_DEFAULT_FTP_PORT)
    If @error Then
        SplashTextOn('ERROR', 'Could Not Connect to ' & GUICtrlRead($IP), 500, 50)
        Sleep(2000)[attachment=16317:FTP_Explorer.zip]
        SplashOff()
        _FTPClose ($XBOX)
        Return 0
    Else
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "IP", "REG_SZ", GUICtrlRead($IP))
        If Not $ipchange = 0 Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "IP", "REG_SZ", $ipchange)
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "User", "REG_SZ", GUICtrlRead($Userbox))
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Bjs FTP Xbox", "Pass", "REG_SZ", GUICtrlRead($Passbox))
        $connected = 1
    EndIf
    Return $conn
EndFunc   ;==>_connect

Func _FTPDownloadFile($l_FTPSession, ByRef $Gui_Progress, ByRef $Gui_Filestatus, $s_FileName, $size, $sv_file, $bufferlen = 16768)
    $time = TimerInit()
    Local $ai_FTPopenfile = DllCall('wininet.dll', 'int', 'FtpOpenFile', 'long', $l_FTPSession, 'str', $s_FileName, 'long', 0x80000000, 'long', 0x00000002, 'long', 0)
    Local $av_InternetReadFile[5] = [0, 0, "", 0, 1]
    Local $v_Struct = DllStructCreate("udword")
    Local $bytes_read = 0, $buf_writ = 0, $prog = 0, $x = 0
    Local $fh = _APIFileOpen ($sv_file)
    Local $buf = DllStructCreate("byte[" & $bufferlen & "]")
    While $av_InternetReadFile[4] <> 0
        $av_InternetReadFile = DllCall('wininet.dll', "int", "InternetReadFile", "long", $ai_FTPopenfile[0], "ptr", DllStructGetPtr($buf), "long", $bufferlen, "ptr", DllStructGetPtr($v_Struct))
        $av_InternetReadFile[4] = DllStructGetData($v_Struct, 1)
        If @error Then
            GUICtrlSetData($Gui_Progress, 0)
            GUICtrlSetData($Gui_Filestatus, '')
            ExitLoop
        ElseIf $av_InternetReadFile[4] < 1 Then
            ExitLoop
        EndIf
        $bytes_read += $av_InternetReadFile[4]
        $Total_Bytes_Read = $Total_Bytes_Read + $av_InternetReadFile[4]
        $buf_writ = _BinaryFileWrite ($fh, $buf)
        If $buf_writ < 1 Then
            GUICtrlSetData($Gui_Progress, 0)
            GUICtrlSetData($Gui_Filestatus, '')
            ExitLoop
        EndIf
        $prog1 = ($bytes_read / $size) * 100
        $prog2 = ($Total_Bytes_Read / $Total_Size) * 100
        $x = $x + 1
        $divs = _MathCheckDiv($x, 5) ; -----stop flickering
        If ($bytes_read/ (TimerDiff($md_Time) / 1000)) > 1048000 Then $divs = _MathCheckDiv($x, 50)
        If $divs = 2 Then
            GUICtrlSetData($Gui_Progress, $prog1)
            GUICtrlSetData($Gui_Filestatus, $s_FileName & '     ' & _Bytes_Convert($bytes_read) & '/' & _Bytes_Convert($size) & '  @  ' & _Bytes_Convert($bytes_read/ (TimerDiff($time) / 1000)) & '/sec')
            GUICtrlSetData($Progress2, $prog2)
            GUICtrlSetData($Total_Progress, _Bytes_Convert($Total_Bytes_Read) & '/' & _Bytes_Convert($Total_Size) & '  @  ' & _Bytes_Convert($Total_Bytes_Read/ (TimerDiff($TTime) / 1000)) & '/sec    ' & $TdFiles & '/' & $TotaldFiles)
        EndIf
    WEnd
    $v_Struct = 0
    DllCall('wininet.dll', "int", "InternetCloseHandle", "long", $ai_FTPopenfile[0])
    _APIFileClose ($fh)
    GUICtrlSetData($Progress1, 0)
    GUICtrlSetData($file_status, '')
    GUICtrlSetData($Progress2, 0)
    GUICtrlSetData($Total_Progress, '')
    Return 0
EndFunc   ;==>_FTPDownloadFile

Func _Get_Download_List()
    Local $download_List
    $download_List = _ArrayCreate($download_List)
    For $i = 0 To _GUICtrlListViewGetItemCount($hList) - 1
        $is_Checked = _GUICtrlListViewGetCheckedState($hList, $i)
        If $is_Checked = 1 Then
            $checked = _GUICtrlListViewGetItemTextArray($hList, $i)
            If $checked[2] = 'DIR' Then
                _Get_Download_Folder_List($FTPconnect, $LastDir, $checked[1], $download_List)
                _GUICtrlListViewSetCheckState($hList, $i, 0)
                ContinueLoop
            EndIf
        EndIf
    Next
    _ArrayAdd($download_List, '$' & $LastDir)
    For $i = 0 To _GUICtrlListViewGetItemCount($hList) - 1
        $is_Checked = _GUICtrlListViewGetCheckedState($hList, $i)
        If $is_Checked = 1 Then
            $checked = _GUICtrlListViewGetItemTextArray($hList, $i)
            If $checked[2] = 'DIR' Then
                _Get_Download_Folder_List($FTPconnect, $LastDir, $checked[1], $download_List)
                _GUICtrlListViewSetCheckState($hList, $i, 0)
                ContinueLoop
            EndIf
            _ArrayAdd($download_List, $LastDir & $checked[1] & '|' & $checked[3])
            _GUICtrlListViewSetCheckState($hList, $i, 0)
        EndIf
    Next
    Return $download_List
EndFunc   ;==>_Get_Download_List

Func _Get_Download_Folder_List($FTPconnect, $Start_Dir, $FTp_dir, ByRef $array)
    Local $change_dir, $list, $backup, $FolderList, $FileList
    $change_dir = $Start_Dir
    $change_dir = $change_dir & $FTp_dir & '/'
    _FtpSetCurrentDir($FTPconnect, $change_dir)
    $FolderList = _FTPFiles_and_Sizes_ListtoArray($FTPconnect, 1, $INTERNET_FLAG_RESYNCHRONIZE)
    If IsArray($FolderList) Then
        _ArraySort($FolderList, 0, 1)
        For $i = 1 To $FolderList[0]
            _Get_Download_Folder_List($FTPconnect, $change_dir, $FolderList[$i], $array)
        Next
    EndIf
    _ArrayAdd($array, '$' & $change_dir)
    $FileList = _FTPFiles_and_Sizes_ListtoArray($FTPconnect, 2, $INTERNET_FLAG_RESYNCHRONIZE)
    If IsArray($FileList) Then
        _ArraySort($FileList, 0, 1)
        For $i = 1 To $FileList[0]
            _ArrayAdd($array, $change_dir & $FileList[$i])
        Next
    EndIf
    $array[0] = UBound($array) - 1
    _FtpSetCurrentDir($FTPconnect, $Start_Dir)
    ;_ArrayDisplay($array)
EndFunc   ;==>_Get_Download_Folder_List

Func _Bytes_Convert($bytes)
    Select
        Case $bytes >= 1048000000
            Return Round($bytes / 1048576000, 1) & ' GB'
        Case $bytes >= 1048000
            Return Round($bytes / 1048576, 1) & ' MB'
        Case $bytes >= 1048
            Return Round($bytes / 1048.576, 1) & ' KB'
        Case Else
            Return $bytes & ' Bytes'
    EndSelect
EndFunc   ;==>_Bytes_Convert

;Modified Functions
Func ListView_DoubleClick()
    If _GUICtrlListViewGetItemText($LISTVIEWCTRL, $LVINFO[0], 1) <> 'DIR' Then Return
    $LastDir = $LastDir & _GUICtrlListViewGetItemText($LISTVIEWCTRL, $LVINFO[0], $LVINFO[1]) & '/'
    _FtpSetCurrentDir($FTPconnect, $LastDir)
    _GetList()
EndFunc   ;==>ListView_DoubleClick

Func _FTPFiles_and_Sizes_ListtoArray($l_FTPSession, $Return_Type = 0, $l_Flags = 0, $l_Context = 0)
    Dim $array, $size
    $array = _ArrayCreate($array)
    $str = "dword;int64;int64;int64;dword;dword;dword;dword;char[256];char[14]"
    $WIN32_FIND_DATA = DllStructCreate($str)
    Local $callFindFirst = DllCall('wininet.dll', 'int', 'FtpFindFirstFile', 'long', $l_FTPSession, 'str', "", 'ptr', DllStructGetPtr($WIN32_FIND_DATA), 'long', $l_Flags, 'long', $l_Context)
    If Not $callFindFirst[0] Then
        SetError(-1)
        Return 0
    EndIf
    $ret = ""
    While 1
        Select
            Case $Return_Type = 0 ; Folders and files
                If DllStructGetData($WIN32_FIND_DATA, 1) = 16 Then
                    _ArrayInsert($array, 1, DllStructGetData($WIN32_FIND_DATA, 9) & '|DIR') ; Add Folder to top of array
                Else
                    If DllStructGetData($WIN32_FIND_DATA, 6) < 0 Then
                        $size = $maxdword + (DllStructGetData($WIN32_FIND_DATA, 6))
                    Else
                        $size = DllStructGetData($WIN32_FIND_DATA, 6)
                    EndIf
                    _ArrayAdd($array, DllStructGetData($WIN32_FIND_DATA, 9) & '|' & $size) ; Add file to array
                EndIf
            Case $Return_Type = 1 ; Folders only
                If DllStructGetData($WIN32_FIND_DATA, 1) = 16 Then
                    _ArrayAdd($array, DllStructGetData($WIN32_FIND_DATA, 9))
                EndIf
            Case $Return_Type = 2 ; Files only
                If DllStructGetData($WIN32_FIND_DATA, 1) <> 16 Then
                    If DllStructGetData($WIN32_FIND_DATA, 6) < 0 Then
                        $size = $maxdword + (DllStructGetData($WIN32_FIND_DATA, 6))
                        ;MsgBox(0, '', DllStructGetData($WIN32_FIND_DATA, 5) & ' | ' & DllStructGetData($WIN32_FIND_DATA, 6) & ' | ' & DllStructGetData($WIN32_FIND_DATA, 7) & ' | ' & DllStructGetData($WIN32_FIND_DATA, 8))
                    Else
                        $size = DllStructGetData($WIN32_FIND_DATA, 6)
                    EndIf
                    If DllStructGetData($WIN32_FIND_DATA, 6) = -1 Then $size = -1
                    ;MsgBox(0,'',DllStructGetData($WIN32_FIND_DATA, 5) &' | ' &DllStructGetData($WIN32_FIND_DATA, 6) & ' | ' & DllStructGetData($WIN32_FIND_DATA, 7) & ' | ' & DllStructGetData($WIN32_FIND_DATA, 8))
                    _ArrayAdd($array, DllStructGetData($WIN32_FIND_DATA, 9) & '|' & $size)
                EndIf
        EndSelect
        Local $callFindNext = DllCall('wininet.dll', 'int', 'InternetFindNextFile', 'long', $callFindFirst[0], 'ptr', DllStructGetPtr($WIN32_FIND_DATA))
        If Not $callFindNext[0] Then
            ExitLoop
        EndIf
    WEnd
    $WIN32_FIND_DATA = 0
    $array[0] = UBound($array) - 1
    $close = DllCall('wininet.dll', "int", "InternetCloseHandle", "long", $callFindFirst[0])
    Return $array
EndFunc   ;==>_FTPFiles_and_Sizes_ListtoArray

Func _FTPGetFileSize($l_FTPSession, $s_FileName)
    Local $size
    Local $ai_FTPGetSizeHandle = DllCall('wininet.dll', 'int', 'FtpOpenFile', 'long', $l_FTPSession, 'str', $s_FileName, 'long', 0x80000000, 'long', 0x04000002, 'long', 0)
    Local $ai_FTPGetFileSize = DllCall('wininet.dll', 'int', 'FtpGetFileSize', 'long', $ai_FTPGetSizeHandle[0], 'long', $size)
    If @error Or $ai_FTPGetFileSize[0] = 0 Then
        $close = DllCall('wininet.dll', 'int', 'InternetCloseHandle', 'long', $ai_FTPGetSizeHandle[0])
        SetError(-1)
        Return 0
    EndIf
    $close = DllCall('wininet.dll', 'int', 'InternetCloseHandle', 'long', $ai_FTPGetSizeHandle[0])
    Return $ai_FTPGetFileSize[0]
EndFunc   ;==>_FTPGetFileSize

;FTP Functions
Func _FTPGetCurrentDir($l_FTPSession)
    Local $ai_FTPGetCurrentDir = DllCall('wininet.dll', 'int', 'FtpGetCurrentDirectory', 'long', $l_FTPSession, 'str', "", 'long_ptr', 260)
    If @error Or $ai_FTPGetCurrentDir[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
    Return $ai_FTPGetCurrentDir[2]
EndFunc   ;==>_FTPGetCurrentDir

Func _FtpSetCurrentDir($l_FTPSession, $s_Remote)
    Local $ai_FTPSetCurrentDir = DllCall('wininet.dll', 'int', 'FtpSetCurrentDirectory', 'long', $l_FTPSession, 'str', $s_Remote)
    If @error Or $ai_FTPSetCurrentDir[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
    Return $ai_FTPSetCurrentDir[2]
EndFunc   ;==>_FtpSetCurrentDir

Func _FTPPutFolderContents($FTPSession, $s_LocalFolder, $s_RemoteFolder, $b_RecursivePut)
    Dim $i
    $search = FileFindFirstFile($s_LocalFolder & "\*.*")
    If $search = -1 Then
        Return $i
    EndIf
    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        If StringInStr(FileGetAttrib($s_LocalFolder & "\" & $file), "D") Then
            _FTPMakeDir ($FTPSession, $s_RemoteFolder & "/" & $file)
            If $b_RecursivePut Then
                _FTPPutFolderContents($FTPSession, $s_LocalFolder & "\" & $file, $s_RemoteFolder & "/" & $file, $b_RecursivePut)
            EndIf
        Else
            _FTPPutFile ($FTPSession, $s_LocalFolder & "\" & $file, $s_RemoteFolder & "/" & $file, 0, 0)
        EndIf
    WEnd
    FileClose($search)
EndFunc   ;==>_FTPPutFolderContents

Func _GetLastError()
    Local $aResult
    $aResult = DllCall("Kernel32.dll", "int", "GetLastError")
    Return $aResult[0]
EndFunc   ;==>_GetLastError

Func _ShowError($sText, $bExit = True)
    MsgBox(16 + 4096, "Error", $sText)
    If $bExit Then Exit
EndFunc   ;==>_ShowError

Func _FormatMessage($iFlags, $pSource, $iMessageID, $iLanguageID, $pBuffer, $iSize, $vArguments)
    Local $aResult
    $aResult = DllCall("Kernel32.dll", "int", "FormatMessageA", "int", $iFlags, "hwnd", $pSource, _
            "int", $iMessageID, "int", $iLanguageID, "ptr", $pBuffer, "int", $iSize, _
            "ptr", $vArguments)
    Return $aResult[0]
EndFunc   ;==>_FormatMessage

Func _GetLastErrorMessage()
    Local $pBuffer, $rBuffer
    $rBuffer = DllStructCreate("char[4096]")
    $pBuffer = DllStructGetPtr($rBuffer)
    _FormatMessage($FORMAT_MESSAGE_FROM_SYSTEM, 0, _GetLastError(), 0, $pBuffer, 4096, 0)
    Return DllStructGetData($rBuffer, 1)
EndFunc   ;==>_GetLastErrorMessage


;Not Working
Func _FTPUploadFile($l_FTPSession, ByRef $Gui_Progress, ByRef $Gui_CurrentFile, $s_FileName, $sv_file, $bufferlen = 1048);----NOT WORKING
    $flags = BitOR($INTERNET_FLAG_TRANSFER_BINARY, $INTERNET_FLAG_NEED_FILE)
    Local $hand = DllStructCreate('hwnd')
    Local $fh = _APIFileOpen ($sv_file)
    ;Local $localfile = _APIFileOpen('c:\coy.avi')
    Local $ai_FTPopenfile = DllCall('wininet.dll', 'int', 'FtpOpenFile', 'long', $l_FTPSession, 'str', $s_FileName, 'long', 0x40000000, 'long', $flags, 'long', 0)
    ;Local $ai_Lockfile = DllCall('wininet.dll', 'int', 'InternetLockRequestFile', 'long', $ai_FTPopenfile[0], 'ptr', DllStructGetPtr($hand))
    Local $Outbytesread = DllStructCreate("udword")
    Local $bytes_read = 0, $buf_writ = 0, $prog = 0, $x = 0, $pos = 0
    Local $sv_fileSize = FileGetSize($sv_file)
    Local $buffer = DllStructCreate("byte[" & $bufferlen & "]")
    Local $exit = 0
    While $sv_fileSize <> 0
        If $sv_fileSize < $bufferlen Then
            $buf_writ = _BinaryFileRead ($fh, $buffer, $sv_fileSize)
            $exit = 1
        Else
            $buf_read = _BinaryFileRead ($fh, $buffer, $bufferlen)
        EndIf
        $av_InternetwriteFile = DllCall('wininet.dll', "int", "InternetwriteFile", "long", $ai_FTPopenfile[0], "ptr", DllStructGetPtr($buffer), "long", $bufferlen, "ptr", DllStructGetPtr($Outbytesread))
        ;$buf_writ = _BinaryFileWrite($localfile, $buf)
        $sv_fileSize = $sv_fileSize - $bufferlen
        If $exit = 1 Then ExitLoop
    WEnd
    $v_Struct = 0
    DllCall('wininet.dll', "int", "InternetCloseHandle", "long", $ai_FTPopenfile[0])
    _APIFileClose ($fh)
    ;_APIFileClose($localfile)
    Return 0
EndFunc   ;==>_FTPUploadFile

;;cache Functions
Func _Navigate_Cache()
    $name = _GUICtrlListViewGetItemTextArray($hList, _GUICtrlListViewGetCurSel($hList))
    $search = _ArraySearch($cacheNames, $LastDir & $name[1] & '/')
    If $search > 0 Then
        _GUICtrlListViewDeleteAllItems($hList)
        $LastDir = $LastDir & $name[1] & '/'
        _FtpSetCurrentDir($FTPconnect, $LastDir)
        $cachedata = $cache[$search]
        For $i = 4 To $cachedata[0]
            $nItem = GUICtrlCreateListViewItem($cachedata[$i], $hList)
        Next
        Return
    EndIf
    _FtpSetCurrentDir($FTPconnect, $LastDir & $name[1] & '/')
    _GetListcache($cache)
    _ArrayAdd($cacheNames, $LastDir & $name[1] & '/')
    $search = _ArraySearch($cacheNames, $LastDir & $name[1] & '/')
    If $search > 0 Then
        _GUICtrlListViewDeleteAllItems($hList)
        $cachedata = $cache[$search]
        For $i = 4 To $cachedata[0]
            $nItem = GUICtrlCreateListViewItem($cachedata[$i], $hList)
        Next
    EndIf
    $LastDir = $LastDir & $name[1] & '/'
    GUICtrlSetData($tdirs, $cachedata[2])
    GUICtrlSetData($tsize, _Bytes_Convert($cachedata[1]))
    GUICtrlSetData($tfiles, $cachedata[3])
EndFunc   ;==>_Navigate_Cache

Func _GetListcache(ByRef $cachedata)
    Local $list
    $list = _ArrayCreate($list)
    $bytes = 0
    $FolderList = _FTPFiles_and_Sizes_ListtoArray($FTPconnect, 1, $INTERNET_FLAG_RESYNCHRONIZE)
    If Not IsArray($FolderList) Then
        _ArrayAdd($list, 'No Items in Directory')
        Return $list
    EndIf
    _ArraySort($FolderList, 0, 1)
    For $i = 1 To $FolderList[0]
        _ArrayAdd($list, $FolderList[$i] & '|DIR')
    Next
    $FileList = _FTPFiles_and_Sizes_ListtoArray($FTPconnect, 2, $INTERNET_FLAG_RESYNCHRONIZE)
    _ArraySort($FileList, 0, 1)
    For $i = 1 To $FileList[0]
        $size = StringSplit($FileList[$i], '|')
        _ArrayAdd($list, $size[1] & '|' & _Bytes_Convert($size[2]) & '|' & $size[2])
        $bytes = $bytes + $size[2]
    Next
    _ArrayInsert($list, 1, $bytes)
    _ArrayInsert($list, 2, $FolderList[0])
    _ArrayInsert($list, 3, $FileList[0])
    $list[0] = UBound($list) - 1
    _ArrayAdd($cachedata, $list)
EndFunc   ;==>_GetListcache

FTP_Explorer.zip

Edited by bchris01

Share this post


Link to post
Share on other sites

another bug..

i cant connect to my ftp by putting in: 67.80.194.73:1055 then my login and pass.. it just give me a connection error

Share this post


Link to post
Share on other sites

another bug..

i cant connect to my ftp by putting in: 67.80.194.73:1055 then my login and pass.. it just give me a connection error

I Think thats bacause the FTP Port is set to 21.

Try changing line 228 to $conn = _FTPConnect ($XBOX, GUICtrlRead($IP), GUICtrlRead($Userbox), GUICtrlRead($Passbox), 1055)

then just put 67.80.194.73 into the server box.

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