File vom Ftp-Server kopieren mit Progressbar?

  • Hi,

    habe folgendes Problem. Und zwar hab ich bei mir zu Hause einen alten Computer zu einem Ftp-Server umfunktioniert.
    Nun möchte ich mit AutoIt eine File vom Server mit einer Progressbar auf meinen Rechner kopieren. Das kopieren ist nicht das Problem, aber wie mach ich es, dass Die Progressbar auch den Fortschritt richtig anzeigt?

    Freue mich über jede Art von Hilfe.

    MfG,

    cannTOice

    2 Mal editiert, zuletzt von cannTOice (26. Januar 2009 um 13:02)

  • Vielleicht hilft dir diese UDF weiter:

    Spoiler anzeigen
    [autoit]

    #include<array.au3>
    Global $GLOBAL_FTP_WININETHANDLE = -1
    Global Const $INTERNET_OPEN_TYPE_DIRECT = 1
    Global Const $INTERNET_OPEN_TYPE_PRECONFIG = 0
    Global Const $INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4
    Global Const $INTERNET_OPEN_TYPE_PROXY = 3

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

    ; Could be called at the End of Script
    ; Closes the wininet.dll used for FTP-Functions
    Func _FTPUnInit()
    DllClose($GLOBAL_FTP_WININETHANDLE)
    $GLOBAL_FTP_WININETHANDLE = -1
    EndFunc ;==>_FTPUnInit

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

    ;===============================================================================
    ;
    ; Function Name: _FTPOpen()
    ; Description: Opens an FTP session.
    ; Parameter(s): $s_Agent - Random name. ( like "myftp" )
    ; $l_AccessType - Set if proxy is used.
    ; $s_ProxyName - ProxyName.
    ; $s_ProxyBypass - ProxyByPasses's.
    ; $l_Flags - Special flags.
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - Returns an indentifier.
    ; On Failure - 0 and sets @ERROR
    ; Remarks: Values for $l_AccessType
    ; $INTERNET_OPEN_TYPE_DIRECT -> no proxy
    ; $INTERNET_OPEN_TYPE_PRECONFIG -> Retrieves the proxy
    ; or direct configuration from the registry.
    ; $INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
    ; -> Retrieves the proxy or direct configuration
    ; from the registry and prevents the use of a
    ; startup Microsoft JScript or Internet Setup (INS) file.
    ; $INTERNET_OPEN_TYPE_PROXY -> Passes requests to the
    ; proxy unless a proxy bypass list is supplied
    ; and the name to be resolved bypasses the proxy.
    ; Then no proxy is used.
    ; Author(s): Wouter van Kesteren.
    ;
    ;===============================================================================

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

    Func _FTPOpen($s_Agent, $l_AccessType = 1, $s_ProxyName = '', $s_ProxyBypass = '', $l_Flags = 0)
    If $GLOBAL_FTP_WININETHANDLE = -1 Then ___FTPInit()
    Local $ai_InternetOpen = DllCall($GLOBAL_FTP_WININETHANDLE, 'long', 'InternetOpen', 'str', $s_Agent, 'long', $l_AccessType, 'str', $s_ProxyName, 'str', $s_ProxyBypass, 'long', $l_Flags)
    If @error Or $ai_InternetOpen[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf

    Return $ai_InternetOpen[0]

    EndFunc ;==>_FTPOpen

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

    ;===============================================================================
    ;
    ; Function Name: _FTPConnect()
    ; Description: Connects to an FTP server.
    ; Parameter(s): $l_InternetSession - The Long from _FTPOpen()
    ; $s_ServerName - Server name/ip.
    ; $s_Username - Username.
    ; $s_Password - Password.
    ; $i_ServerPort - Server port ( 0 is default (21) )
    ; $l_Service - I dont got a clue what this does.
    ; $l_Flags - Special flags.
    ; $l_Context - I dont got a clue what this does.
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - Returns an indentifier.
    ; On Failure - 0 and sets @ERROR
    ; Author(s): Wouter van Kesteren
    ;
    ;===============================================================================

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

    Func _FTPConnect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_Passive = 0, $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0)

    If $i_Passive == 1 Then $l_Flags = 0x08000000
    Local $ai_InternetConnect = DllCall($GLOBAL_FTP_WININETHANDLE, 'long', 'InternetConnect', 'long', $l_InternetSession, 'str', $s_ServerName, 'int', $i_ServerPort, 'str', $s_Username, 'str', $s_Password, 'long', $l_Service, 'long', $l_Flags, 'long', $l_Context)

    If @error Or $ai_InternetConnect[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf

    Return $ai_InternetConnect[0]

    EndFunc ;==>_FTPConnect

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

    ;===============================================================================
    ;
    ; Function Name: _FTPPutFile()
    ; Description: Puts an file on an FTP server.
    ; Parameter(s): $l_FTPSession - The Long from _FTPConnect()
    ; $s_LocalFile - The local file.
    ; $s_RemoteFile - The remote Location for the file.
    ; $l_Flags - Special flags.
    ; $l_Context - I dont got a clue what this does.
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - 1
    ; On Failure - 0
    ; Author(s): Wouter van Kesteren
    ;
    ;===============================================================================

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

    Func _FTPPutFile($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0)

    Local $ai_FTPPutFile = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context)
    If @error Or $ai_FTPPutFile[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf

    Return $ai_FTPPutFile[0]

    EndFunc ;==>_FTPPutFile

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

    ;===============================================================================
    ;
    ; Function Name: _FTPDelFile()
    ; Description: Delete an file from an FTP server.
    ; Parameter(s): $l_FTPSession - The Long from _FTPConnect()
    ; $s_RemoteFile - The remote Location for the file.
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - 1
    ; On Failure - 0
    ; Author(s): Wouter van Kesteren
    ;
    ;===============================================================================

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

    Func _FTPDelFile($l_FTPSession, $s_RemoteFile)

    Local $ai_FTPPutFile = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpDeleteFile', 'long', $l_FTPSession, 'str', $s_RemoteFile)
    If @error Or $ai_FTPPutFile[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf

    Return $ai_FTPPutFile[0]

    EndFunc ;==>_FTPDelFile

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

    ;===============================================================================
    ;
    ; Function Name: _FTPRenameFile()
    ; Description: Renames an file on an FTP server.
    ; Parameter(s): $l_FTPSession - The Long from _FTPConnect()
    ; $s_Existing - The old file name.
    ; $s_New - The new file name.
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - 1
    ; On Failure - 0
    ; Author(s): Wouter van Kesteren
    ;
    ;===============================================================================

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

    Func _FTPRenameFile($l_FTPSession, $s_Existing, $s_New)

    Local $ai_FTPRenameFile = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpRenameFile', 'long', $l_FTPSession, 'str', $s_Existing, 'str', $s_New)
    If @error Or $ai_FTPRenameFile[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf

    Return $ai_FTPRenameFile[0]

    EndFunc ;==>_FTPRenameFile

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

    ;===============================================================================
    ;
    ; Function Name: _FTPMakeDir()
    ; Description: Makes an Directory on an FTP server.
    ; Parameter(s): $l_FTPSession - The Long from _FTPConnect()
    ; $s_Remote - The Directory to Create.
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - 1
    ; On Failure - 0
    ; Author(s): Wouter van Kesteren
    ;
    ;===============================================================================

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

    Func _FTPMakeDir($l_FTPSession, $s_Remote)

    Local $ai_FTPMakeDir = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpCreateDirectory', 'long', $l_FTPSession, 'str', $s_Remote)
    If @error Or $ai_FTPMakeDir[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf

    Return $ai_FTPMakeDir[0]

    EndFunc ;==>_FTPMakeDir

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

    ;===============================================================================
    ;
    ; Function Name: _FTPDelDir()
    ; Description: Delete's an Directory on an FTP server.
    ; Parameter(s): $l_FTPSession - The Long from _FTPConnect()
    ; $s_Remote - The Directory to be deleted.
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - 1
    ; On Failure - 0
    ; Author(s): Wouter van Kesteren
    ;
    ;===============================================================================

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

    Func _FTPDelDir($l_FTPSession, $s_Remote)

    Local $ai_FTPDelDir = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpRemoveDirectory', 'long', $l_FTPSession, 'str', $s_Remote)
    If @error Or $ai_FTPDelDir[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf

    Return $ai_FTPDelDir[0]

    EndFunc ;==>_FTPDelDir

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

    ;===============================================================================
    ;
    ; Function Name: _FTPClose()
    ; Description: Closes the _FTPOpen session.
    ; Parameter(s): $l_InternetSession - The Long from _FTPOpen()
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - 1
    ; On Failure - 0
    ; Author(s): Wouter van Kesteren
    ;
    ;===============================================================================

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

    Func _FTPClose($l_InternetSession)

    Local $ai_InternetCloseHandle = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'InternetCloseHandle', 'long', $l_InternetSession)
    If @error Or $ai_InternetCloseHandle[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf

    Return $ai_InternetCloseHandle[0]

    EndFunc ;==>_FTPClose

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

    ;===============================================================================
    ;
    ; Function Name: _FTPGetCurrentDir()
    ; Description: Get Current Directory on an FTP server.
    ; Parameter(s): $l_FTPSession - The Long from _FTPConnect()
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - Directory Name
    ; On Failure - 0
    ; Author(s): Beast
    ;
    ;===============================================================================

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

    Func _FTPGetCurrentDir($l_FTPSession)

    Local $ai_FTPGetCurrentDir = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpGetCurrentDirectory', 'long', $l_FTPSession, 'str', "", 'long*', 260)
    If @error Or $ai_FTPGetCurrentDir[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf

    Return $ai_FTPGetCurrentDir[2]


    EndFunc ;==>_FTPGetCurrentDir

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

    ;===============================================================================
    ;
    ; Function Name: _FtpSetCurrentDir()
    ; Description: Set Current Directory on an FTP server.
    ; Parameter(s): $l_FTPSession - The Long from _FTPConnect()
    ; $s_Remote - The Directory to be set.
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - 1
    ; On Failure - 0
    ; Author(s): Beast
    ;
    ;===============================================================================

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

    Func _FtpSetCurrentDir($l_FTPSession, $s_Remote)

    Local $ai_FTPSetCurrentDir = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpSetCurrentDirectory', 'long', $l_FTPSession, 'str', $s_Remote)
    If @error Or $ai_FTPSetCurrentDir[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf

    Return $ai_FTPSetCurrentDir[0]


    EndFunc ;==>_FtpSetCurrentDir

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

    ;===============================================================================
    ;
    ; Function Name: _FTPGetFile()
    ; Description: Get file from a FTP server.
    ; Parameter(s): $l_FTPSession - The Long from _FTPConnect()
    ; $s_RemoteFile - The remote Location for the file.
    ; $s_LocalFile - The local file.
    ; $l_Flags - Special flags.
    ; $l_Context - I dont got a clue what this does.
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - 1
    ; On Failure - 0
    ; Author(s): Wouter van Kesteren
    ;
    ;===============================================================================

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

    Func _FTPGetFile($l_FTPSession, $s_RemoteFile, $s_LocalFile, $l_Flags = 0, $l_Context = 0)

    Local $ai_FTPGetFile = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpGetFile', 'long', $l_FTPSession, 'str', $s_RemoteFile, 'str', $s_LocalFile, 'long', $l_Flags, 'long', $l_Context)
    If @error Or $ai_FTPGetFile[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf

    Return $ai_FTPGetFile[0]

    EndFunc ;==>_FTPGetFile

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

    ;===============================================================================
    ;
    ; Function Name: _FTPGetFileSize()
    ; Description: Gets filesize of a file on the FTP server.
    ; Parameter(s): $l_FTPSession - The Long from _FTPConnect()
    ; $s_FileName - The file name.
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - 1
    ; On Failure - 0
    ; Author(s): J.o.a.c.h.i.m. d.e. K.o.n.i.n.g.
    ;
    ;===============================================================================

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

    Func _FTPGetFileSize($l_FTPSession, $s_FileName)

    Local $ai_FTPGetSizeHandle = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpOpenFile', 'long', $l_FTPSession, 'str', $s_FileName, 'long', 0x80000000, 'long', 0x04000002, 'long', 0)
    Local $ai_FTPGetFileSize = DllCall($GLOBAL_FTP_WININETHANDLE, 'dword', 'FtpGetFileSize', 'long', $ai_FTPGetSizeHandle[0], 'dword*', 0)
    If @error Or $ai_FTPGetFileSize[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf
    DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'InternetCloseHandle', 'str', $l_FTPSession)

    ;~ Return $ai_FTPGetFileSize[0]
    Return BitOR(BitShift($ai_FTPGetFileSize[2], -32), BitAND($ai_FTPGetFileSize[0], 0xFFFFFFFF))

    EndFunc ;==>_FTPGetFileSize

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

    Func _FTPListFiles($l_FTPSession, $l_Flags = 0, $l_Context = 0)
    Local $str, $ret, $search,$file,$WIN32_FIND_DATA
    $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
    MsgBox(0, "Folder Empty", "No Files Found ")
    SetError(-1)
    Return 0
    EndIf
    $ret = ""
    While 1
    If DllStructGetData($WIN32_FIND_DATA, 1) <> 16 Then $ret = $ret & DllStructGetData($WIN32_FIND_DATA, 9) & "|"
    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
    Return StringTrimRight($ret, 1)
    EndFunc ;==>_FTPListFiles

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

    ;===============================================================================
    ;
    ; Function Name: _FtpFileListto2DArray()
    ; Description: Get Filenames and filesizes of a Directory.
    ; Parameter(s): $Remote_Dir - The Directory to be set.
    ; $Server - Server address
    ; $username - User name
    ; $pass - Password
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - 1
    ; On Failure - 0
    ; Author(s): Beast
    ;
    ;===============================================================================
    Func _FTPFileListTo2DArray($Remote_Dir, $server = '', $username = '', $pass = '')
    Local $2DArray[1]
    ;~ $2DArray = _ArrayCreate($2DArray)
    $Open = _FTPOpen('xbox')
    $Conn = _FTPConnect($Open, $server, $username, $pass, 1)
    $setdir = _FtpSetCurrentDir($Conn, $Remote_Dir)
    $cdir = _FTPGetCurrentDir($Conn)
    $files = _FTPFilesListToArray($Conn, 2)
    $max = UBound($files)
    ReDim $2DArray[$max][2]
    For $i = 0 To $files[0]
    $2DArray[$i][0] = $files[$i]
    Next
    $Ftpc = _FTPClose($Open)
    $Totalsize = 0
    $end = $2DArray[0][0]
    ProgressOn('FTP', 'Getting File Sizes...')
    For $i = 1 To $end
    $Open = _FTPOpen('xbox')
    $Conn = _FTPConnect($Open, $server, $username, $pass, 1)
    $setdir = _FtpSetCurrentDir($Conn, '/F/Videos/')
    $size = _FTPGetFileSize($Conn, $2DArray[$i][0])
    $2DArray[$i][1] = $size
    $size = Round($size / 1048576, 1)
    $Totalsize = $size + $Totalsize
    $Ftpc = _FTPClose($Open)
    ProgressSet(($i / $end) * 100, Round(($i / $end) * 100, 1) & ' % ' & $2DArray[$i][0], $end - $i & ' Files ' & $Totalsize & ' MB Total')
    Next
    ProgressOff()
    $2DArray[0][1] = $Totalsize
    Return $2DArray
    EndFunc ;==>_FTPFileListTo2DArray

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

    ;===============================================================================
    ;
    ; Function Name: _FtpFileListtoArray()
    ; Description: Get Filenames, Directorys, or Both of a Directory.
    ; Parameter(s): $l_FTPSession - Long From _FileConnect
    ; $Return_type - 0 = Both Files and Directorys, 1 = Directorys, 2 = Files
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - 1
    ; On Failure - 0
    ; Author(s): Beast
    ;
    ;===============================================================================

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

    Func _FTPFilesListToArray($l_FTPSession, $Return_Type = 0, $l_Flags = 0, $l_Context = 0)
    Dim $array[1], $array2d[1]
    ;~ $array = _ArrayCreate($array)
    ;~ $array2d = _ArrayCreate($array2d)
    $str = "dword;int64;int64;int64;dword;dword;dword;dword;char[256];char[14]"
    $WIN32_FIND_DATA = DllStructCreate($str)
    Local $callFindFirst = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpFindFirstFile', 'long', $l_FTPSession, 'str', "", 'ptr', DllStructGetPtr($WIN32_FIND_DATA), 'long', $l_Flags, 'long', $l_Context)
    If Not $callFindFirst[0] Then
    MsgBox(0, "Folder Empty", "No Files Found ")
    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)) ; Add Folder to top of array
    Else
    _ArrayAdd($array, DllStructGetData($WIN32_FIND_DATA, 9)) ; Add folder to array
    EndIf
    Case $Return_Type = 1 ; Folders only
    If DllStructGetData($WIN32_FIND_DATA, 1) = 16 Then _ArrayAdd($array, DllStructGetData($WIN32_FIND_DATA, 9))
    Case $Return_Type = 2 ; Files only
    If DllStructGetData($WIN32_FIND_DATA, 1) <> 16 Then _ArrayAdd($array, DllStructGetData($WIN32_FIND_DATA, 9))
    EndSelect
    Local $callFindNext = DllCall($GLOBAL_FTP_WININETHANDLE, '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
    Return $array
    EndFunc ;==>_FTPFilesListToArray

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

    Const $INTERNET_FLAG_PASSIVE = 0x08000000
    Const $INTERNET_FLAG_TRANSFER_ASCII = 0x00000001
    Const $INTERNET_FLAG_TRANSFER_BINARY = 0x00000002
    Const $INTERNET_DEFAULT_FTP_PORT = 21
    Const $INTERNET_SERVICE_FTP = 1

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

    ;===============================================================================
    ;
    ; Function Name: _FTPCommand()
    ; Description: Sends a command to an FTP server.
    ; Parameter(s): $l_FTPSession - The Long from _FTPOpen()
    ; $s_FTPCommand - Commad string to send to FTP Server
    ; $l_ExpectResponse - Data socket for response in Async mode
    ; $s_Context - A pointer to a variable that contains an application-defined
    ; value used to identify the application context in callback operations
    ; $s_Handle - A pointer to a handle that is created if a valid data socket is opened.
    ; The $s_ExpectResponse parameter must be set to TRUE for phFtpCommand to be filled.
    ;
    ; Requirement(s): DllCall, wininet.dll
    ; Return Value(s): On Success - Returns an indentifier.
    ; On Failure - 0 and sets @ERROR
    ; Author(s): Bill Mezian
    ;
    ; Command Examples: depends on server syntax. The following is for
    ; Binary transfer, ASCII transfer, Passive transfer mode (used with firewalls)
    ; 'type I' 'type A' 'pasv'
    ;
    ;===============================================================================

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

    Func _FTPCommand($l_FTPSession, $s_FTPCommand, $l_Flags = 0x00000001, $l_ExpectResponse = 0, $l_Context = 0, $s_Handle = '')

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

    Local $ai_FTPCommand = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpCommand', 'long', $l_FTPSession, 'long', $l_ExpectResponse, 'long', $l_Flags, 'str', $s_FTPCommand, 'long', $l_Context, 'ptr', $s_Handle)
    If @error Or $ai_FTPCommand[0] = 0 Then
    SetError(-1)
    Return 0
    EndIf
    ;Return $s_return
    Return $ai_FTPCommand[0]

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

    EndFunc ;==>_FTPCommand

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

    ;======================================================================================================
    ;
    ; Function Name: _FTPPutFolderContents()
    ; Description: Puts an folder on an FTP server. Recursivley if selected
    ; Parameter(s): $l_InternetSession - The Long from _FTPConnect()
    ; $s_LocalFolder - The local folder i.e. "c:\temp".
    ; $s_RemoteFolder - The remote folder i.e. '/website/home'.
    ; $b_RecursivePut - Recurse through sub-dirs. 0=Non recursive, 1=Recursive
    ; Requirement(s): DllCall, wininet.dll
    ; Author(s): Stumpii
    ;
    ;======================================================================================================

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

    Func _FTPPutFolderContents($l_InternetSession, $s_LocalFolder, $s_RemoteFolder, $b_RecursivePut)

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

    ; Shows the filenames of all files in the current directory.
    $search = FileFindFirstFile($s_LocalFolder & "\*.*")

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

    ; Check if the search was successful
    If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
    EndIf

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

    While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    If StringInStr(FileGetAttrib($s_LocalFolder & "\" & $file), "D") Then
    _FTPMakeDir($l_InternetSession, $s_RemoteFolder & "/" & $file)
    If $b_RecursivePut Then
    _FTPPutFolderContents($l_InternetSession, $s_LocalFolder & "\" & $file, $s_RemoteFolder & "/" & $file, $b_RecursivePut)
    EndIf
    Else
    _FTPPutFile($l_InternetSession, $s_LocalFolder & "\" & $file, $s_RemoteFolder & "/" & $file, 0, 0)
    EndIf
    WEnd

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

    ; Close the search handle
    FileClose($search)

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

    EndFunc ;==>_FTPPutFolderContents

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

    #Region Internal
    ;Internal Func, DO NOT USE YOURSELF
    Func ___FTPInit()
    $GLOBAL_FTP_WININETHANDLE = DllOpen('wininet.dll')
    EndFunc ;==>___FTPInit
    #EndRegion Internal
    ;===============================================================================
    ;
    ; Function Name: _FTP_UploadProgress()
    ; Description:: Uploadsd 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.
    ; $s_RemoteFile - The remote Location for the 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:
    ; -3 -> Create File failed
    ; -4 -> Write to file failed
    ; -5 -> Close File failed
    ; Upload 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_UploadProgress, 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_UploadProgress($l_FTPSession, $s_LocalFile, $s_RemoteFile, $FunctionToCall = "")
    #Region Declaration
    Local $ai_ftpopenfile, $ai_InternetCloseHandle, $fhandle, $glen, $last, $x, $parts, $buffer, $ai_ftpwrite, $result, $out, $i
    #EndRegion Declaration
    #Region OpenFile
    Local $ai_ftpopenfile = DllCall($GLOBAL_FTP_WININETHANDLE, 'long', 'FtpOpenFile', 'long', $l_FTPSession, 'str', $s_RemoteFile, 'dword', 0x40000000, 'dword', 0x02, 'dword', 0)
    If @error Or $ai_ftpopenfile[0] = 0 Then
    SetError(-3)
    Return 0
    EndIf
    #EndRegion OpenFile
    If $FunctionToCall = "" Then ProgressOn("FTP Upload", "Uploading " & $s_LocalFile)
    #Region DataSend
    Local $fhandle = FileOpen($s_LocalFile, 16)

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

    $glen = 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
    $buffer = DllStructCreate("byte[" & $x & "]")

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

    ;~ Dim $out, $i = 0, $result
    For $i = 1 To $parts
    Select
    Case $i = 101 And $last > 0
    $x = $last
    EndSelect
    DllStructSetData($buffer, 1, FileRead($fhandle, $x))

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

    SetError(-4)
    Return 0
    EndIf

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

    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', 'long', $ai_ftpopenfile[0])
    DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpDeleteFile', 'long', $l_FTPSession, 'str', $s_RemoteFile)
    FileClose($fhandle)
    SetError(-6)
    Return $ret
    EndSelect
    EndSwitch
    Sleep(20)

    [/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', 'long', $ai_ftpopenfile[0])
    If @error Or $ai_InternetCloseHandle[0] = 0 Then
    SetError(-5)
    Return 0
    EndIf
    #EndRegion disconnect

    Return 1
    EndFunc ;==>_FTP_UploadProgress

    [/autoit] [autoit][/autoit] [autoit][/autoit] [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, 'long', 'FtpOpenFile', 'long', $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 Upload", "Uploading " & $s_LocalFile)
    #Region DataSend
    Local $ai_FTPGetFileSize = DllCall($GLOBAL_FTP_WININETHANDLE, 'dword', 'FtpGetFileSize', 'long', $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
    $buffer = DllStructCreate("byte[" & $x & "]")

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

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

    Local $ai_FTPread = DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'InternetReadFile', 'long', $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', 'long', $ai_ftpopenfile[0])
    FileClose($fhandle)

    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', 'long', $ai_ftpopenfile[0])
    ;~ DllCall($GLOBAL_FTP_WININETHANDLE, 'int', 'FtpDeleteFile', 'long', $l_FTPSession, 'str', $s_RemoteFile)
    FileClose($fhandle)
    FileDelete($s_LocalFile)
    SetError(-6)
    Return $ret
    EndSelect
    EndSwitch
    Sleep(20)

    [/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', 'long', $ai_ftpopenfile[0])
    If @error Or $ai_InternetCloseHandle[0] = 0 Then
    SetError(-5)
    Return 0
    EndIf
    #EndRegion disconnect

    Return 1
    EndFunc ;==>_FTP_DownloadProgress

    [/autoit]
  • einfach so:

    Spoiler anzeigen
    [autoit]


    $file = ""
    $tofolder = ""
    $size = InetGetSize($file)
    InetGet($file, $tofolder, 1, 1)

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

    ProgressOn("Progress Meter", "Increments every second", "0 percent")
    $i = 0
    While @InetGetActive
    $cursize = FileGetSize($tofolder)
    $i = Round(($cursize / $size) * 100, 2)
    ProgressSet( $i, $i & " percent")
    WEnd
    ProgressSet(100 , "Done", "Complete")
    sleep(500)
    ProgressOff()

    [/autoit]

    MFG FireFlyer

    *Paradox ist, wenn man sich im Handumdrehen den Fuss bricht* :D