Jump to content

FTP Download Progress bar?


Recommended Posts

Is there a way to measure how many bytes have been downloaded when using _FTP_FileGet? I am trying to get a working Progress bar that actually displays progress.

I tried using the _FTP_ProgressDownload but it doesn't seem to read the progress in real time. The progress bar sits at 0 unitl the download is finished then it goes to 100%.

So far this is what I have BUT the progress bar won't update until I actually open the folder in explorer and hit refresh (F5). O.o Huh? Anyway... It's in two files. I would love some help on this one because it's driving me nuts.

TEST1.EXE

#include <FTPEx.au3>

$latestversion = "1"
$server = "localhost"
$port = 7227

$Open = _FTP_Open('MyFTP Control')
$Conn = _FTP_Connect($Open, $server, "USERNAME", "PASSWORD", 1, $port)
$sFileSize = _FTP_FileGetSize($Conn, "800MBFILE.EXE")
_FTP_Close($Open)

ProgressOn("800MBFILE", "Downloading " & "800MBFILE " & $LatestVersion & "...", "0%", 0, 0)

$_Pid = Run("test2.exe")
$Pct = 0

While ProcessExists ($_Pid)
If $Pct = 100 Then ExitLoop
Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
$BytesReceived = FileGetSize(@TempDir & "800MBFILE.EXE") ;Get bytes received
$Pct = Int($BytesReceived / $sFileSize * 100) ;Calculate percentage
ProgressSet($Pct, $Pct & "%") ;Set progress bar
WEnd

ProgressSet(100,"Download Complete!")
Sleep(2000)
ProgressOff()

_FTP_Close($Open)

and TEST2.EXE

#include <FTPEx.au3>

$server = "localhost"
$port = 7227

$Open = _FTP_Open('MyFTP Control')
$Conn = _FTP_Connect($Open, $server, "USERNAME", "PASSWORD", 1, $port)
_FTP_FileGet($Conn,  "800MBFILE.EXE", @TempDir & "800MBFILE.EXE")
_FTP_Close($Open)
Edited by thepaulguy
Link to post
Share on other sites

The data is held in a buffer/temporary file until its finshed. Thats why it goes from 0 to 100 so fast. Its possible to get byte progress using _FTP_SetStatusCallback() but it can get a little tricky. _FTP_ProgressDownload() is certainly the easy route. There might have been something wrong in your script if you want to post whatever you tried before.

Edited by Beege
Link to post
Share on other sites

I went with this instead of the FTPex.au3.

$LatestVersion=1
$Protocol="ftp"
$server = "localhost"
$port = 7227

ProgressOn("800MBFILE", "Downloading " & "800MBFILE " & $LatestVersion & "...", "0%")
$url = $Protocol & "://USERNAME:PASSWORD@" & $Server & ":" & $Port & "/800MBFILE.EXE";Set URL
Local $hDownload = InetGet($url, @TempDir & "800MBFILE.EXE", 1, 1)
$FileSize = InetGetSize($url) ;Get file size

While Not InetGetInfo($hDownload, 2) ;Loop until download is finished
Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
$BytesReceived = InetGetInfo($hDownload, 0) ;Get bytes received
$Pct = Int($BytesReceived / $FileSize * 100) ;Calculate percentage
ProgressSet($Pct, $Pct & "%") ;Set progress bar
WEnd

ProgressSet(100,"Download Complete!")
Sleep(2000)
ProgressOff()
InetClose($hDownload)
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...