_FTP_DownloadProgress()

  • Hallo,
    ich komme mit der Funktion nicht weiter ^^
    Sie ist in der FTP_Ex.au3 enthalten und sieht folgendermaßen aus:

    Spoiler anzeigen
    [autoit]

    ;===============================================================================
    ;
    ; Function Name: _FTP_DownloadProgress()
    ; Description:: Downloads a file in Binary Mode and shows Progress in Tooltip or by Calling a User defined Function
    ; Parameter(s): $l_FTPSession - The Long from _FTPConnect()
    ; $s_LocalFile - The local file to create.
    ; $s_RemoteFile - The remote source file.
    ; $FunctionToCall - [Optional] A function which can update a Progressbar and
    ; react on UserInput like Click on Abort or Close App.
    ; (More info in the end of this comment)
    ; Requirement(s): ??
    ; Return Value(s): Success: 1
    ; Error: 0 and @error:
    ; -1 -> Local file couldn't be created
    ; -3 -> Open RemoteFile failed
    ; -4 -> Read from Remotefile failed
    ; -5 -> Close RemoteFile failed
    ; Download aborted by PercentageFunc:
    ; ReturnValue: Return of Called Function
    ; And @error -6
    ; Author(s): limette, Prog@ndy
    ;
    ; Information about $FunctionToCall:
    ; Parameter: $Percentage - The Percentage of Progress
    ; Return Values: Continue Download - 1
    ; Abort Download - 0 Or negative
    ; These Return Values are returned by _FTP_DownloadProgress, too,
    ; so you can react on different Actions like Aborting by User, closing App or TimeOut of whatever
    ; Examples:
    ;~ Func _UpdateProgress($Percentage)
    ;~ ProgressSet($percent,$percent &"%")
    ;~ If _IsPressed("77") Then Return 0 ; Abort on F8
    ;~ Return 1 ; bei 1 Fortsetzten
    ;~ Endfunc
    ;
    ;~ Func _UpdateProgress($Percentage)
    ;~ GUICtrlSetData($ProgressBarCtrl,$percent)
    ;~ Switch GUIGetMsg()
    ;~ Case $GUI_EVENT_CLOSE
    ;~ Return -1 ; _FTP_UploadProgress Aborts with -1, so you can exit you app afterwards
    ;~ Case $Btn_Cancel
    ;~ Return 0 ; Just Cancel, without special Return value
    ;~ EndSwitch
    ;~ Return 1 ; Otherwise contine Upload
    ;~ Endfunc
    ;
    ;===============================================================================
    ;
    Func _FTP_DownloadProgress($l_FTPSession, $s_LocalFile, $s_RemoteFile, $FunctionToCall = "")
    #Region Declaration
    Local $ai_ftpopenfile, $ai_InternetCloseHandle, $fhandle, $glen, $last, $x, $parts, $buffer, $ai_FTPread, $result, $out, $i
    #EndRegion Declaration
    #Region OpenFile
    Local $fhandle = FileOpen($s_LocalFile, 18)
    If @error Then
    SetError(-1)
    Return 0
    EndIf
    Local $ai_ftpopenfile = DllCall($GLOBAL_FTP_WININETHANDLE, 'ptr', 'FtpOpenFile', 'hwnd', $l_FTPSession, 'str', $s_RemoteFile, 'dword', 0x80000000, 'dword', 0x02, 'dword', 0)
    If @error Or $ai_ftpopenfile[0] = 0 Then
    SetError(-3)
    Return 0
    EndIf
    #EndRegion OpenFile
    If $FunctionToCall = "" Then ProgressOn("FTP Download", "Downloading " & $s_LocalFile)
    #Region DataSend
    Local $ai_FTPGetFileSize = DllCall($GLOBAL_FTP_WININETHANDLE, 'dword', 'FtpGetFileSize', 'ptr', $ai_ftpopenfile[0], 'dword*', 0)
    $glen = BitOR(BitShift($ai_FTPGetFileSize[2], -32), BitAND($ai_FTPGetFileSize[0], 0xFFFFFFFF)) ;FileGetSize($s_LocalFile)
    $last = Mod($glen, 100)
    $x = ($glen - $last) / 100
    ;~ If $x = 0 Then $x = 1
    If $x = 0 Then
    $x = $last
    $parts = 1
    ElseIf $last > 0 Then
    $parts = 101
    Else
    $parts = 100
    EndIf
    If $x < $last Then
    $buffer = DllStructCreate("byte[" & $last & "]")
    Else
    $buffer = DllStructCreate("byte[" & $x & "]")
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;~ Dim $out, $i = 0, $result
    For $i = 1 To $parts
    Select
    Case $i = 101 And $last > 0
    $x = $last
    EndSelect

    [/autoit] [autoit][/autoit] [autoit]

    Local $ai_FTPread = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'InternetReadFile', 'ptr', $ai_ftpopenfile[0], 'ptr', DllStructGetPtr($buffer), 'int', $x, 'dword*', $out)
    If @error Or $ai_FTPread[0] = 0 Then
    $ai_InternetCloseHandle = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'InternetCloseHandle', 'ptr', $ai_ftpopenfile[0])
    FileClose($fhandle)

    [/autoit] [autoit][/autoit] [autoit]

    SetError(-4)
    Return 0
    EndIf
    FileWrite($fhandle, BinaryMid(DllStructGetData($buffer, 1), 1, $ai_FTPread[4]))
    Switch $FunctionToCall
    Case ""
    ProgressSet($i)
    Case Else
    Select
    Case $parts = 1
    $result = 100
    Case $i = 101
    $result = 100
    Case Else
    $result = $i
    EndSelect
    $ret = Call($FunctionToCall, $result)
    Select
    Case $ret <= 0
    $ai_InternetCloseHandle = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'InternetCloseHandle', 'ptr', $ai_ftpopenfile[0])
    ;~ DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpDeleteFile', 'hwnd', $l_FTPSession, 'str', $s_RemoteFile)
    FileClose($fhandle)
    FileDelete($s_LocalFile)
    SetError(-6)
    Return $ret
    EndSelect
    EndSwitch
    Sleep(10)

    [/autoit] [autoit][/autoit] [autoit]

    Next

    [/autoit] [autoit][/autoit] [autoit]

    FileClose($fhandle)
    #EndRegion DataSend
    If $FunctionToCall = "" Then ProgressOff()
    #Region disconnect
    $ai_InternetCloseHandle = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'InternetCloseHandle', 'ptr', $ai_ftpopenfile[0])
    If @error Or $ai_InternetCloseHandle[0] = 0 Then
    SetError(-5)
    Return 0
    EndIf
    #EndRegion disconnect

    [/autoit] [autoit][/autoit] [autoit]

    Return 1
    EndFunc ;==>_FTP_DownloadProgress

    [/autoit]

    Und so habe ich sie in mein Skript eingebaut:

    Spoiler anzeigen
    [autoit]

    _FTP_DownloadProgress($Conn, "C:\Test.txt", "\\Test.txt")

    [/autoit]

    Immer bekomme ich :
    @error

    -.-
    Hat jemand einen Vorschlag?

    Einmal editiert, zuletzt von PokerFace (27. August 2009 um 16:19)