Jump to content

Ftp Downloader With Progress Bar


slemke
 Share

Recommended Posts

Hi @all,

I have adapted some snippets from here to download the most recent signatures for NAV via FTP. It finds the file with a wildcard-mask using the _FtpFileFindFirst from ftp.au3. The status of the download is indicated by a progress bar. Perhaps someone needs something like this. The Username/Pass/Server/Directory is stored in extra variables.

The example works out-of-the-box.

Regards and thanks for a fantasitc AutoIT!

Sebastian

ftp.au3

FTP_Progress.au3

Link to comment
Share on other sites

  • 8 months later...

Corrected BIG BUG:

There must be closed handle for FTPGetSizeHandle:

Func _FTPGetFileSize($l_FTPSession, $s_FileName)

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

    Return $ai_FTPGetFileSize[0]
    
EndFunc ;==> _FTPGetFileSize()oÝ÷ Ù8^­ì±Éh±çajweyú+3ìzË"¢v®¶­sdFÆÄ6ÆÂb33·vææWBæFÆÂb33²Âb33¶çBb33²Âb33´çFW&æWD6Æ÷6TæFÆRb33²Âb33·7G"b33²Âb33c¶ÅôeE6W76öâ

so after calling this function was closed whole FTP session (connection)

Edited by Zedna
Link to comment
Share on other sites

  • 3 weeks later...

hi everybody

this is a post for a friend :whistle:

------

first i had to comment out "If @error Then Failed("Open") & If @error Then Failed("Connect")" to successfully run this script

after that it seemed that the download has started - anyway the file was available on hdd - BUT the progressbar was not visible and the script did NOT shutdown tidly - unfortunately i had to shutdown this script manually....by the way the two @error requests had no effect to this script.....maybe this is a unique error

autoit rules^^

snoozer

ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°$₪Ǿَ€Яº¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø

Link to comment
Share on other sites

  • 2 years later...

Hi snoozer,

I'm not sure if this helps, but I did the bug fix that Zedna pointed out above and everything seems to be working for me. I'm running Vista. Here is how I have modified slemke's original code (mostly removed the German).

#include <GUIConstantsEx.au3>
#include 'ftp.au3'

$server = 'ftp.symantec.com'
$username = 'anonymous'
$pass = 'pass'
$ftp_dir = '/public/english_us_canada/antivirus_definitions/symantec_antivirus_corp/'
$ftp_file_mask = '*-i64.exe*'
$target_dir = @ScriptDir & "\"

$DownloadNow = MsgBox(4, "Downloader", "Would you like to download the latest defs now?")

If $DownloadNow = 6 Then
    Download();you don't need to use call
Else
    ;just continue
EndIf

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)
        ProgressSet($Percent, "Downloaded - " & $filedownload & " Mb")
        TrayTip("Downloading...", "Downloaded = " & $filedownload & " Mb", 10, 16)
        Sleep(250)
    WEnd
    ProgressOff()
EndFunc   ;==>Download

Hope this helps,

-Mike

Edited by mdwerne
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...