Jump to content
Sign in to follow this  
mdwerne

Variable loop or maybe an array?

Recommended Posts

mdwerne

Hello,

Still trying to learn a bit more by taking working code and asking for help in optimizing it. What I have below is my modification to this code (thanks for the start slemke & Zedna): FTP with Progress Bar

What I'm looking to do is improve how the different values for $ftp_dir and $ftp_file_mask are called. Not sure if a loop is the way to go or somehow with an array. What I'm really looking for a better (more optimized) method than I have...maybe something where the files are transferred in parallel instead serially.

Thanks for any suggestions.

-Mike

#include <GUIConstantsEx.au3>
#include <File.au3>
#include 'ftp.au3'
FileDelete(@ScriptDir & "\Files\*.*")
$server = 'ftp.symantec.com'
$username = 'anonymous'
$pass = 'pass'
$ftp_dir = '/public/english_us_canada/antivirus_definitions/symantec_antivirus_corp/'
$target_dir = @ScriptDir & "\Files\"
$ftp_file_mask = '*-x86.exe'
Download()
$ftp_file_mask = '*-i64.exe'
Download()
$ftp_dir = '/public/english_us_canada/antivirus_definitions/symantec_antivirus_corp/jdb/'
$ftp_file_mask = '*.jdb'
Download()
$ftp_dir = '/public/english_us_canada/antivirus_definitions/symantec_antivirus_corp/vdb/'
$ftp_file_mask = '*.vdb'
Download()
$ftp_dir = '/public/english_us_canada/antivirus_definitions/symantec_antivirus_corp/xdb/'
$ftp_file_mask = '*.xdb'
Download()
Func Download()
    ; FTP.au3 Init -
    $Open = _FTPOpen('MyFTP Control')
    ;If @error Then Failed("Open")
    If @error Then MsgBox(0, "ERROR", "Failed to open")
    $Conn = _FTPConnect($Open, $server, $username, $pass, 21)
    ;If @error Then Failed("Connect")
    If @error Then MsgBox(0, "ERROR", "Failed to connect")

    Dim $Handle
    Dim $DllRect

    $FileInfo = _FtpFileFindFirst($Conn, $ftp_dir & $ftp_file_mask, $Handle, $DllRect)
    If $FileInfo[0] Then
        Do
            $dl_file = $FileInfo[10]
            $FileInfo = _FtpFileFindNext($Handle, $DllRect)

        Until Not $FileInfo[0]
    EndIf
    _FtpFileFindClose($Handle, $DllRect)

    _FTPClose($Open)
    ;---------------------------------

    ; ftp-Connect-String
    $ftp_conn_string = "ftp://" & $username & ":" & $pass & "@" & $server & $ftp_dir & $dl_file

    ; you must set progress on before loop
    ;;;ProgressOn("Download " & $dl_file, "", "", -1, -1, 16)

    InetGet($ftp_conn_string, $target_dir & $dl_file, 1, 1)

    ; need to divide by 1048576 also, variables that don't change should be outside loop
    $FileSize = InetGetSize($ftp_conn_string) / 1048576
    While @InetGetActive
        $filedownload = Round(@InetGetBytesRead / 1048576, 2)

        ;need to mutliply by 10 to get percentage
        $Percent = Round(($filedownload / $FileSize) * 100)
        $FileSizeMB = Round($FileSize, -1)
        ;;;;ProgressSet($Percent, "Downloaded - " & $filedownload & " Mb")
        ;;;;
        TrayTip("Downloading " & $dl_file, "Downloaded = " & $filedownload & " of " & $FileSizeMB & " MB's so far.", 10, 16)
        Sleep(250)
    WEnd
    ;;;;ProgressOff()
EndFunc   ;==>Download

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.