Lädt eine Datei im Binärmodus herunter und zeigt entweder ein Fortschrittsfenster an oder ruft dazu eine Benutzerfunktion auf
#include <FTPEx.au3>
_FTP_ProgressDownload ( $hFTPSession, $sLocalFile, $sRemoteFile [, $hFunctionToCall = 0] )
$hFTPSession | FTP-Handle, wie von _FTP_Connect(). |
$sLocalFile | Die lokale Zieldatei. |
$sRemoteFile | Die Quelldatei auf dem FTP-Server. |
$hFunctionToCall | [optional] Eine Variable die mit der Benutzerfunktion verknüpft ist, um eine Forschrittsleiste zu aktualisieren oder auf Benutzerinteraktionen wie z. B. das abbrechen oder verlassen des Prozesses, zu reagieren. Standard = keine. Siehe Bemerkungen. |
Erfolg: | 1 |
Fehler: | 0 und setzt das @error Flag auf ungleich null: |
@error: | -1 - Lokale Datei konnte nicht erstellt werden -2 - Ermitteln der Remotedateigröße nicht möglich -3 - Quelldatei konnte nicht geöffnet werden -4 - Fehler beim Lesen der Quelldatei -5 - Schließen der Quelldatei fehlgeschlagen -6 - Download durch Benutzerfunktion abgebrochen, deren Rückgabewert wurde zurückgegeben -7 - Das Schreiben der lokalen Datei fehlgeschlagen |
Informationen zu $hFunctionToCall:
Parameter: $iPercentage - Der Fortschritt in Prozent
Rückgabewerte:
Download fortsetzen - 1
Download abbrechen - 0 oder kleiner als 0 z. B. 0 oder -1
Diese Rückgabewerte werden dann von _FTP_ProgressUpload() zurückgegeben, sodass auf verschiedene Ereignisse wie Abbruch durch den Benutzer, Beenden des Programms oder TimeOut des Prozesses reagiert werden kann.
#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
#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
; *******************************************************
; Beispiel 1
; *******************************************************
;
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <FTPEx.au3>
#include <Misc.au3>
Opt('MustDeclareVars', 1)
_example1()
_example2()
#cs
Beispiel mit externem Progressfenster zur Demonstration der Fortschrittsanzeige mit einer Benutzerfunktion
#ce
Func _example1()
Local $s_ServerName = 'ftp.csx.cam.ac.uk' ;das ist ein real existierender Server
Local $s_Username = ''
Local $s_Password = ''
Local $i_Passive = 0 ;aktive Verbindung nutzen wenn bei anderen Server Probleme dann auch mit 1 für passive Verbindung testen
Local $l_InternetSession, $l_FTPSession
Local $errOpen, $errFTP
If FileExists(@TempDir & "\tmp.tmp") Then FileDelete(@TempDir & "\tmp.tmp") ;Nur um sicherzustellen dass die Datei nicht existiert
$l_InternetSession = _FTP_Open('AuoItZilla') ;Öffnet eine FTP Sitzung
$errOpen = @error
If Not @error Then
$l_FTPSession = _FTP_Connect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_Passive) ;Verbindet zu einem FTP Server
$errFTP = @error
If Not @error Then
ProgressOn("Download", "Status:", "coded autoBert 2011")
_FTP_ProgressDownload($l_FTPSession, @ScriptDir & "\tmp.tmp", "README", "_UpdateProgress")
If @error Then ConsoleWrite("Fehler bei _FTP_ProgressDownload: " & @error)
ProgressOff()
Else
MsgBox(0, "Connect", "fehlgeschlagen")
ConsoleWrite("Connect: " & " " & $errFTP & @CRLF)
EndIf
Else
MsgBox(0, "Open", "fehlgeschlagen")
ConsoleWrite("Open " & " " & $errOpen & @CRLF)
EndIf
_FTP_Close($l_InternetSession)
EndFunc ;==>_example1
Func _UpdateProgress($Prozent)
ProgressSet($Prozent, $Prozent & "%")
If _IsPressed("77") Then Return 0 ; Abbruch bei F8
Return 1 ; bei 1 fortsetzen
EndFunc ;==>_UpdateProgress
#cs
Beispiel mit eingebauter Fortschrittsanzeige von _FTP_ProgressDownload
#ce
Func _example2()
Local $s_ServerName = 'ftp.csx.cam.ac.uk' ;das ist ein real existierender Server
Local $s_Username = ''
Local $s_Password = ''
Local $i_Passive = 0 ;aktive Verbindung nutzen wenn bei anderen Server Probleme dann auch mit 1 für passive Verbung testen
Local $l_InternetSession, $l_FTPSession
Local $errOpen, $errFTP
If FileExists(@TempDir & "\tmp.tmp") Then FileDelete(@TempDir & "\tmp.tmp") ;Nur um sicherzustellen dass die Datei nicht existiert
$l_InternetSession = _FTP_Open('AuoItZilla') ;Öffnet eine FTP Sitzung
$errOpen = @error
If Not @error Then
$l_FTPSession = _FTP_Connect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_Passive) ;Verbindet zu einem FTP Server
$errFTP = @error
If Not @error Then
_FTP_ProgressDownload($l_FTPSession, @ScriptDir & "\tmp.tmp", "README")
If @error Then ConsoleWrite("Fehler bei _FTP_ProgressDownload: " & @error)
Else
MsgBox(0, "Connect", "fehlgeschlagen")
ConsoleWrite("Connect: " & " " & $errFTP & @CRLF)
EndIf
Else
MsgBox(0, "Open", "fehlgeschlagen")
ConsoleWrite("Open " & " " & $errOpen & @CRLF)
EndIf
_FTP_Close($l_InternetSession)
EndFunc ;==>_example2