FTP

  • Guten Abend zusammen,
    dies hier wäre meine Letzte Frage für heute:
    Hier erst mal mein Code:

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <ProgressConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <FTPEx.au3>
    $Open = _FTP_Open('FTP')
    $server = ''
    $username = ''
    $pass = ''
    $Conn = _FTP_Connect($Open, $server, $username, $pass)
    $erconn = @error


    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Installtion wird gestartet", 613, 201, 192, 132)
    $Button1 = GUICtrlCreateButton("Abbrechen", 448, 168, 75, 25)
    $Button2 = GUICtrlCreateButton("Download", 528, 168, 75, 25)
    $percent = GUICtrlCreateProgress(8, 40, 598, 29)
    $Label1 = GUICtrlCreateLabel("Installationskomponenten werden Heruntergeladen...", 8, 8, 498, 28)
    GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif")
    $Group1 = GUICtrlCreateGroup("Status Informationen", 8, 80, 593, 81)
    $Label2 = GUICtrlCreateLabel("Pfad: " &@ScriptDir&"\"&@ScriptName, 16, 104, 235, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $KBS = GUICtrlCreateLabel("KB\s: Beispiel... 150", 16, 120, 235, 20)
    $MB = GUICtrlCreateLabel("Größe: 1 von 1,4 MB", 16, 136, 245, 20)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###


    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button2
    _FTP_ProgressDownload($Conn,@UserProfileDir&"\Test.bmp","Test.bmp", "_UpdateProgress")
    EndSwitch
    WEnd


    Func _UpdateProgress($Percentage)
    GUICtrlSetData($percent,$percent &"%")
    If _IsPressed("77") Then Return 0 ; Abort on F8
    Return 1 ; bei 1 Fortsetzten
    Endfunc


    Wie kann ich nun die Download gewindigkeit und die schon heruntergeladenen MB's anzeigen ?

    MFG:
    Cpatcha aka Marcel

    Einmal editiert, zuletzt von Captcha (29. Oktober 2012 um 19:53)

  • Hallo Captcha,

    indem du es errechnest. Ich befürchte aber das die Dateigrösse (FileGetSize) nicht aktualisiert wird so dass keine Rechnung möglch ist, ansonsten benötogst du noch _FTP_FileGetSize, TimerInt und TimerDiff

    edit:

    Spoiler anzeigen
    [autoit]

    #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    #include <FTPEx.au3>
    #include <Misc.au3>

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

    Opt('MustDeclareVars', 1)

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

    Global $progressbar1, $Fortschritt, $DLKBs, $iSizeRemote, $iStart
    Global $sFileLocal = @ScriptDir & "\tmp.tmp"

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

    _example1()

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

    Func _example1()
    GUICreate("Dings", 220, 250, 100, 200, -1)
    $Fortschritt = GUICtrlCreateLabel("", 10, 35, 200,22)
    $DLKBs = GUICtrlCreateLabel("", 10, 60, 200,22)
    GUISetState(@SW_SHOW)
    $progressbar1 = GUICtrlCreateProgress(10, 10, 200, 20)
    Local $s_ServerName = 'ftp.csx.cam.ac.uk' ;das ist ein real exitierender Server
    Local $s_Username = ''
    Local $s_Password = ''
    Local $i_Passive = 0 ;aktive Verbindung nutzen wenn bei anderen Server Probleme dann ach mit 1 für passive Verbung testen
    Local $l_InternetSession, $l_FTPSession
    Local $errOpen, $errFTP
    Local $sFileRemote = "/pub/software/databases/training/SRPMS/ucs-training-public-1.0.2-1.src.rpm"
    If FileExists($sFileLocal) Then FileDelete($sFileLocal) ;Nur um sicher zustellen dass das File nicht existiert

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

    $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
    $iStart = TimerInit()
    $iSizeRemote = _FTP_FileGetSize($l_FTPSession, $sFileRemote)
    _FTP_ProgressDownload($l_FTPSession, $sFileLocal, $sFileRemote, "_UpdateProgress")
    If @error Then ConsoleWrite("Fehler bei _FTP_ProgressDownload: " & @error)
    _UpdateProgress(100)
    Else
    ConsoleWrite("Connect: " & " " & $errFTP & @CRLF)
    EndIf
    Else
    MsgBox(0, "Open", "fehlgeschalagen")
    ConsoleWrite("Open " & " " & $errOpen & @CRLF)
    EndIf
    _FTP_Close($l_InternetSession)
    EndFunc ;==>_example1

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

    Func _UpdateProgress($Prozent)
    Local $iDiff = TimerDiff($iStart), $iDone = $iSizeRemote/100*$Prozent, $iKBs = Round($iDone/$iDiff/1.024,2)
    ConsoleWrite($iDone & "/" & $iSizeRemote & @TAB & $iDiff & @CRLF)
    GUICtrlSetData($progressbar1, $Prozent)
    GUICtrlSetData($Fortschritt, StringReplace(Round($iDone/1024,3) & " KB",".",","))
    GUICtrlSetData($DLKBs, StringReplace($iKBs & " KB/s",".",","))
    Switch GUIGetMsg()
    Case - 3
    Return -1 ; _FTP_DownloadProgress Aborts with -1, so you can exit you app afterwards
    EndSwitch

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

    Return 1 ; Otherwise contine DownloadEndFunc ;==>_UpdateProgress
    EndFunc ;==>_UpdateProgress

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

    beruht darauf dass _FTP_ProgressDownload die Remotedtei in 100 Päckchen aufteilt. Du bist dir aber bewusst das du dieses Programm nicht weitergeben darfst, ansonsten läufst du Gefahr dass dein FTP-Account übernommen wird. Einzige Ausnahme er ist eh öffentlich also ohne Zugangsdaten.

    mfg autobert

    2 Mal editiert, zuletzt von autoBert (28. Oktober 2012 um 22:17)