Function Reference


_FTP_ProgressDownload

Downloads a file in Binary Mode and shows a Progress window or by Calling a User defined Function

#include <FTPEx.au3>
_FTP_ProgressDownload ( $hFTPSession, $sLocalFile, $sRemoteFile [, $hFunctionToCall = 0] )

Parameters

$hFTPSession as returned by _FTP_Connect().
$sLocalFile The local file to create.
$sRemoteFile The remote source file.
$hFunctionToCall [optional] A variable assigned to the user defined function to update a progress bar or react on user interation, such as aborting or exiting the process. Default = none. See remarks.

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero.
@error: -1 - Local file couldn't be created
-2 - Unable to get RemoteFile size
-3 - Open RemoteFile failed
-4 - Read from Remotefile failed
-5 - Close RemoteFile failed
-6 - Download aborted by PercentageFunc and Return of Called Function
-7 - Local file write failed

Remarks

Information about $hFunctionToCall:
    Parameter: $iPercentage - The Percentage of Progress
    Return Values:
        Continue Download - 1
        Abort Download    - zero or less than zero e.g. 0 or -1
    These Return Values are returned by _FTP_ProgressUpload(), too, so you can react on different Actions like Aborting by User, closing App or TimeOut of the process.

Example

Example 1

#include <FTPEx.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <ProgressConstants.au3>

;~ Global $g_sRemoteFile = "pub/papers/graphics/research/skin.qt"
Global $g_sRemoteFile = "20MB.zip"
Global $g_sLocalFile = @TempDir & "\temp.tmp"
FileDelete($g_sLocalFile)

;~ Local $sServer = 'ftp.cs.brown.edu' ; Brown Computer Science
Local $sServer = 'speedtest.tele2.net' ; Tele2 Speedtest Service
Local $sUsername = ''
Local $sPass = ''

Local $hInternetSession = _FTP_Open('MyFTP Control')
; passive allows most protected FTPs to answer
Local $hFTPSession = _FTP_Connect($hInternetSession, $sServer, $sUsername, $sPass, 1)

Example()

_FTP_Close($hInternetSession)

Func Example()
        Local $fuFunctionToCall = _UpdateProgress
        ProgressOn("Download Progress", $g_sRemoteFile)
        _FTP_ProgressDownload($hFTPSession, $g_sLocalFile, $g_sRemoteFile, $fuFunctionToCall)
        ProgressOff()
EndFunc   ;==>Example

Func _UpdateProgress($iPercent)
        ProgressSet($iPercent, Int($iPercent) & "%")
        If _IsPressed("77") Then Return 0 ; Abort on F8
        Return 1 ; 1 to continue Download
EndFunc   ;==>_UpdateProgress

Example 2

#include <FTPEx.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>

;~ Global $g_sRemoteFile = "pub/papers/graphics/research/skin.qt"
Global $g_sRemoteFile = "20MB.zip"
Global $g_sLocalFile = @TempDir & "\temp.tmp"
FileDelete($g_sLocalFile)

;~ Local $sServer = 'ftp.cs.brown.edu' ; Brown Computer Science
Local $sServer = 'speedtest.tele2.net' ; Tele2 Speedtest Service
Local $sUsername = ''
Local $sPass = ''

Local $hInternetSession = _FTP_Open('MyFTP Control')
; passive allows most protected FTPs to answer
Local $hFTPSession = _FTP_Connect($hInternetSession, $sServer, $sUsername, $sPass, 1)

Global $g_idProgressBarCtrl, $g_idBtn_Cancel
Example()

_FTP_Close($hInternetSession)

Func Example()
        ; create GUI
        GUICreate("My GUI download Progressbar", 220, 100, 100, 200)
        GUICtrlCreateLabel($g_sRemoteFile, 10, 10)
        $g_idProgressBarCtrl = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
        GUICtrlSetColor(-1, 32250); not working with Windows XP Style
        $g_idBtn_Cancel = GUICtrlCreateButton("Cancel", 75, 70, 70, 20)
        GUISetState(@SW_SHOW)

        Local $fuFunctionToCall = _UpdateGUIProgressBar
        _FTP_ProgressDownload($hFTPSession, $g_sLocalFile, $g_sRemoteFile, $fuFunctionToCall)
EndFunc   ;==>Example

Func _UpdateGUIProgressBar($iPercent)
        GUICtrlSetData($g_idProgressBarCtrl, $iPercent)
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        Exit -1 ; _FTP_DownloadProgress Aborts with -1, so you can exit your app afterwards
                Case $g_idBtn_Cancel
                        Exit -2 ; Just Cancel, without special Return value
        EndSwitch
        Return 1 ; Otherwise continue Download
EndFunc   ;==>_UpdateGUIProgressBar